56 #include "StChain/StChainOpt.h"
60 #include "StETofCollection.h"
61 #include "StETofHeader.h"
62 #include "StETofDigi.h"
64 #include "StMuDSTMaker/COMMON/StMuDst.h"
65 #include "StMuDSTMaker/COMMON/StMuETofDigi.h"
66 #include "StMuDSTMaker/COMMON/StMuETofHeader.h"
68 #include "StETofCalibMaker.h"
69 #include "StETofUtil/StETofHardwareMap.h"
70 #include "StETofUtil/StETofConstants.h"
72 #include "tables/St_etofCalibParam_Table.h"
73 #include "tables/St_etofElectronicsMap_Table.h"
74 #include "tables/St_etofStatusMap_Table.h"
75 #include "tables/St_etofTimingWindow_Table.h"
76 #include "tables/St_etofSignalVelocity_Table.h"
77 #include "tables/St_etofDigiTotCorr_Table.h"
78 #include "tables/St_etofDigiTimeCorr_Table.h"
79 #include "tables/St_etofDigiSlewCorr_Table.h"
80 #include "tables/St_etofResetTimeCorr_Table.h"
81 #include "tables/St_etofPulserTotPeak_Table.h"
82 #include "tables/St_etofPulserTimeDiffGbtx_Table.h"
83 #include "tables/St_etofGet4State_Table.h"
85 namespace etofSlewing {
86 const unsigned int nTotBins = 30;
89 const float conversionFactor = 1. / 100.;
99 mFileNameCalibParam(
"" ),
100 mFileNameElectronicsMap(
"" ),
101 mFileNameStatusMap(
"" ),
102 mFileNameTimingWindow(
"" ),
103 mFileNameSignalVelocity(
"" ),
104 mFileNameCalibHistograms(
"" ),
105 mFileNameResetTimeCorr(
"" ),
106 mFileNamePulserTotPeak(
"" ),
107 mFileNamePulserTimeDiffGbtx(
"" ),
109 mGet4TotBinWidthNs( 1. ),
110 mMinDigisPerSlewBin( 25 ),
111 mResetTimeCorr( 0. ),
115 mPulserPeakTime( 0. ),
116 mReferencePulserIndex( 0 ),
117 mStrictPulserHandling( 0 ),
118 mUsePulserGbtxDiff( true ),
122 mFileNameGet4State(
""),
136 LOG_DEBUG <<
"StETofCalibMaker::ctor" << endm;
139 mTimingWindow.clear();
140 mPulserWindow.clear();
141 mSignalVelocity.clear();
142 mDigiTotCorr.clear();
143 mDigiSlewCorr.clear();
145 mPulserPeakTot.clear();
146 mPulserTimeDiff.clear();
147 mPulserTimeDiffGbtx.clear();
148 mNPulsersCounter.clear();
149 mNStatusBitsCounter.clear();
150 mPulserPresent.clear();
152 mJumpingPulsers.clear();
154 mUnlockPulserState.clear();
156 mStuckFwDigi.clear();
163 StETofCalibMaker::~StETofCalibMaker()
171 StETofCalibMaker::Init()
173 LOG_INFO <<
"StETofCalibMaker::Init()" << endm;
183 StETofCalibMaker::InitRun( Int_t runnumber )
185 mRunYear = ( runnumber + 727000 ) / 1000000 + 1999;
186 LOG_INFO <<
"runnumber: " << runnumber <<
" --> year: " << mRunYear << endm;
189 std::ifstream paramFile;
206 for(
int i=0; i < eTofConst::nGet4sInSystem; i++){
207 mGet4StateMap[i] = 0;
208 if(i < (eTofConst::nGet4sInSystem/2)){
209 mGet4DefaultStateMap[i] = 0;
212 readGet4State(mGlobalCounter , 0);
215 if( mFileNameElectronicsMap.empty() ) {
216 LOG_INFO <<
"etofElectronicsMap: no filename provided --> load database table" << endm;
218 dbDataSet = GetDataBase(
"Geometry/etof/etofElectronicsMap" );
220 St_etofElectronicsMap* etofElectronicsMap =
static_cast< St_etofElectronicsMap*
> ( dbDataSet->
Find(
"etofElectronicsMap" ) );
221 if( !etofElectronicsMap ) {
222 LOG_ERROR <<
"unable to get the electronics map from the database" << endm;
229 LOG_INFO <<
"etofElectronicsMap: filename provided --> use parameter file: " << mFileNameElectronicsMap.c_str() << endm;
239 if( mFileNameStatusMap.empty() ) {
240 LOG_INFO <<
"etofStatusMap: no filename provided --> load database table" << endm;
242 dbDataSet = GetDataBase(
"Calibrations/etof/etofStatusMap" );
244 St_etofStatusMap* etofStatusMap =
static_cast< St_etofStatusMap*
> ( dbDataSet->
Find(
"etofStatusMap" ) );
245 if( !etofStatusMap ) {
246 LOG_ERROR <<
"unable to get the status map from the database" << endm;
250 etofStatusMap_st* statusMapTable = etofStatusMap->GetTable();
252 for(
size_t i=0; i<eTofConst::nChannelsInSystem; i++ ) {
253 mStatus[ channelToKey( i ) ] = (int) statusMapTable->status[ i ];
257 LOG_INFO <<
"etofStatusMap: filename provided --> use parameter file: " << mFileNameStatusMap.c_str() << endm;
259 paramFile.open( mFileNameStatusMap.c_str() );
261 if( !paramFile.is_open() ) {
262 LOG_ERROR <<
"unable to get the 'etofStatusMap' parameters from file --> file does not exist" << endm;
266 std::vector< int > status;
268 while( paramFile >> temp ) {
269 status.push_back( temp );
274 if( status.size() != eTofConst::nChannelsInSystem ) {
275 LOG_ERROR <<
"parameter file for 'etofStatusMap' has not the right amount of entries: ";
276 LOG_ERROR << status.size() <<
" instead of " << eTofConst::nChannelsInSystem <<
" !!!!" << endm;
280 for(
size_t i=0; i<eTofConst::nChannelsInSystem; i++ ) {
281 mStatus[ channelToKey( i ) ] = status[ i ];
285 for(
const auto& kv : mStatus ) {
286 LOG_DEBUG <<
"channel key: " << kv.first <<
" --> status = " << kv.second << endm;
292 mTimingWindow.clear();
293 mPulserWindow.clear();
295 if( mFileNameTimingWindow.empty() ) {
296 LOG_INFO <<
"etofTimingWindow: no filename provided --> load database table" << endm;
298 dbDataSet = GetDataBase(
"Calibrations/etof/etofTimingWindow" );
300 St_etofTimingWindow* etofTimingWindow =
static_cast< St_etofTimingWindow*
> ( dbDataSet->
Find(
"etofTimingWindow" ) );
301 if( !etofTimingWindow ) {
302 LOG_ERROR <<
"unable to get the timing window from the database" << endm;
306 etofTimingWindow_st* timingWindowTable = etofTimingWindow->GetTable();
308 for(
size_t i=0; i<12 ; i++ ) {
309 int key = timingWindowTable->afckAddress[ i ];
311 mTimingWindow[ key ] = std::make_pair( timingWindowTable->timingMin[ i ], timingWindowTable->timingMax[ i ] );
312 mPulserWindow[ key ] = std::make_pair( timingWindowTable->pulserMin[ i ], timingWindowTable->pulserMax[ i ] );
314 mPulserPeakTime = timingWindowTable->pulserPeak[ i ];
319 LOG_INFO <<
"etofTimingWindow: filename provided --> use parameter file: " << mFileNameTimingWindow.c_str() << endm;
321 paramFile.open( mFileNameTimingWindow.c_str() );
323 if( !paramFile.is_open() ) {
324 LOG_ERROR <<
"unable to get the 'etofTimingWindow' parameters from file --> file does not exist" << endm;
329 std::vector< float > times;
333 while( std::getline( paramFile, temp ) ) {
334 std::istringstream istring( temp );
337 istring >>std::hex >> address >> std::dec;
339 while( istring >> time ) {
340 times.push_back( time );
343 if( times.size() != 6 ) {
344 LOG_ERROR <<
"parameter file for 'etofTimingWindow' has not the right amount of entries: ";
345 LOG_ERROR <<
"times for address (0x" << std::hex << address << std::dec <<
") has " << times.size() <<
" instead of " << 6 <<
" !!!!" << endm;
350 mTimingWindow[ address ] = std::make_pair( times.at( 0 ), times.at( 1 ) );
351 mPulserWindow[ address ] = std::make_pair( times.at( 3 ), times.at( 4 ) );
353 mPulserPeakTime = times.at( 5 );
358 if( mTimingWindow.size() > 12 ) {
359 LOG_ERROR <<
" too many entries in mTimingWindow map ...." << endm;
362 if( mPulserWindow.size() > 12 ) {
363 LOG_ERROR <<
" too many entries in mPulserWindow map ...." << endm;
368 for(
const auto& kv : mTimingWindow ) {
369 LOG_DEBUG <<
"AFCK address: 0x" << std::hex << kv.first << std::dec <<
" --> timing window from " << kv.second.first <<
" to " << kv.second.second <<
" ns" << endm;
371 for(
const auto& kv : mPulserWindow ) {
372 LOG_DEBUG <<
"AFCK address: 0x" << std::hex << kv.first << std::dec <<
" --> pulser window from " << kv.second.first <<
" to " << kv.second.second <<
" ns" << endm;
374 LOG_DEBUG <<
"pulser time peak at " << mPulserPeakTime <<
" ns" << endm;
378 if( mFileNameCalibParam.empty() ) {
379 LOG_INFO <<
"etofCalibParam: no filename provided --> load database table" << endm;
381 dbDataSet = GetDataBase(
"Calibrations/etof/etofCalibParam" );
383 St_etofCalibParam* etofCalibParam =
static_cast< St_etofCalibParam*
> ( dbDataSet->
Find(
"etofCalibParam" ) );
384 if( !etofCalibParam ) {
385 LOG_ERROR <<
"unable to get the calibration params from the database" << endm;
389 etofCalibParam_st* calibParamTable = etofCalibParam->GetTable();
391 mGet4TotBinWidthNs = calibParamTable->get4TotBinWidthNs;
392 mMinDigisPerSlewBin = calibParamTable->minDigisInSlewBin;
395 if( mReferencePulserIndex == 0 ) {
396 mReferencePulserIndex = calibParamTable->referencePulserIndex;
399 LOG_INFO <<
"--- reference pulser index is set manually ---" << endm;
403 LOG_INFO <<
"etofCalibParam: filename provided --> use parameter file: " << mFileNameCalibParam.c_str() << endm;
405 paramFile.open( mFileNameCalibParam.c_str() );
407 if( !paramFile.is_open() ) {
408 LOG_ERROR <<
"unable to get the 'etofCalibParam' parameters from file --> file does not exist" << endm;
412 std::vector< float > param;
414 while( paramFile >> temp ) {
415 param.push_back( temp );
420 if( param.size() != 3 ) {
421 LOG_ERROR <<
"parameter file for 'etofCalibParam' has not the right amount of entries: ";
422 LOG_ERROR << param.size() <<
" instead of 3 !!!!" << endm;
426 if( param.at( 0 ) > 0. ) {
427 mGet4TotBinWidthNs = param.at( 0 );
429 if( param.at( 1 ) > 0 ) {
430 mMinDigisPerSlewBin = param.at( 1 );
434 if( param.at( 2 ) > 0 && mReferencePulserIndex == 0 ) {
435 mReferencePulserIndex = param.at( 2 );
438 LOG_INFO <<
"--- reference pulser index is set manually ---" << endm;
442 LOG_INFO <<
" Get4 TOT bin width to ns conversion factor: " << mGet4TotBinWidthNs << endm;
443 LOG_INFO <<
" minimal number of digis required in slewing bin: " << mMinDigisPerSlewBin << endm;
444 LOG_INFO <<
" reference pulser index: " << mReferencePulserIndex << endm;
450 mSignalVelocity.clear();
452 if( mFileNameSignalVelocity.empty() ) {
453 LOG_INFO <<
"etofSignalVelocity: no filename provided --> load database table" << endm;
455 dbDataSet = GetDataBase(
"Calibrations/etof/etofSignalVelocity" );
457 St_etofSignalVelocity* etofSignalVelocity =
static_cast< St_etofSignalVelocity*
> ( dbDataSet->
Find(
"etofSignalVelocity" ) );
458 if( !etofSignalVelocity ) {
459 LOG_ERROR <<
"unable to get the signal velocity from the database" << endm;
463 etofSignalVelocity_st* velocityTable = etofSignalVelocity->GetTable();
465 for(
size_t i=0; i<eTofConst::nCountersInSystem; i++ ) {
466 if( velocityTable->signalVelocity[ i ] > 0 ) {
467 mSignalVelocity[ detectorToKey( i ) ] = velocityTable->signalVelocity[ i ];
472 LOG_INFO <<
"etofSignalVelocity: filename provided --> use parameter file: " << mFileNameSignalVelocity.c_str() << endm;
474 paramFile.open( mFileNameSignalVelocity.c_str() );
476 if( !paramFile.is_open() ) {
477 LOG_ERROR <<
"unable to get the 'etofSignalVelocity' parameters from file --> file does not exist" << endm;
481 std::vector< float > velocity;
483 while( paramFile >> temp ) {
484 velocity.push_back( temp );
489 if( velocity.size() != eTofConst::nCountersInSystem ) {
490 LOG_ERROR <<
"parameter file for 'etofSignalVelocity' has not the right amount of entries: ";
491 LOG_ERROR << velocity.size() <<
" instead of " << eTofConst::nCountersInSystem <<
" !!!!" << endm;
495 for(
size_t i=0; i<eTofConst::nCountersInSystem; i++ ) {
496 if( velocity.at( i ) > 0 ) {
497 mSignalVelocity[ detectorToKey( i ) ] = velocity.at( i );
502 for(
const auto& kv : mSignalVelocity ) {
503 LOG_DEBUG <<
"counter key: " << kv.first <<
" --> signal velocity = " << kv.second <<
" cm / ns" << endm;
509 mDigiTotCorr.clear();
510 mDigiTimeCorr.clear();
511 mDigiSlewCorr.clear();
513 if( mFileNameCalibHistograms.empty() ) {
517 LOG_INFO <<
"etofDigiTotCorr: no filename provided --> load database table" << endm;
519 dbDataSet = GetDataBase(
"Calibrations/etof/etofDigiTotCorr" );
521 St_etofDigiTotCorr* etofDigiTotCorr =
static_cast< St_etofDigiTotCorr*
> ( dbDataSet->
Find(
"etofDigiTotCorr" ) );
522 if( !etofDigiTotCorr ) {
523 LOG_ERROR <<
"unable to get the digi tot correction from the database" << endm;
527 etofDigiTotCorr_st* digiTotCorrTable = etofDigiTotCorr->GetTable();
529 for(
size_t i=0; i<eTofConst::nChannelsInSystem; i++ ) {
530 unsigned int key = channelToKey( i );
531 unsigned int detector = key / 1000;
533 if( mDigiTotCorr.count( detector ) == 0 ) {
534 TString name = Form(
"digiTotCorr_%d", detector );
535 mDigiTotCorr[ detector ] =
new TH1F( name, name, 2 * eTofConst::nStrips, 0, 2 * eTofConst::nStrips );
538 unsigned int strip = ( key % 1000 ) / 10;
539 unsigned int side = key % 10;
542 LOG_DEBUG << i <<
" " << detector <<
" " << strip <<
" " << side <<
" " << digiTotCorrTable->totCorr[ i ] << endm;
545 mDigiTotCorr.at( detector )->SetBinContent( strip + eTofConst::nStrips * ( side - 1 ) , digiTotCorrTable->totCorr[ i ] );
548 for(
auto& kv : mDigiTotCorr ) {
549 kv.second->SetDirectory( 0 );
556 LOG_INFO <<
"etofDigiTimeCorr: no filename provided --> load database table" << endm;
559 dbDataSet = GetDataBase(
"Calibrations/etof/etofDigiTimeCorr" );
561 St_etofDigiTimeCorr* etofDigiTimeCorr =
static_cast< St_etofDigiTimeCorr*
> ( dbDataSet->
Find(
"etofDigiTimeCorr" ) );
562 if( !etofDigiTimeCorr ) {
563 LOG_ERROR <<
"unable to get the digi time correction from the database" << endm;
567 etofDigiTimeCorr_st* digiTimeCorrTable = etofDigiTimeCorr->GetTable();
569 for(
size_t i=0; i<eTofConst::nChannelsInSystem; i++ ) {
570 unsigned int key = channelToKey( i );
571 unsigned int detector = key / 1000;
573 if( mDigiTimeCorr.count( detector ) == 0 ) {
574 TString name = Form(
"digiTimeCorr_%d", detector );
575 mDigiTimeCorr[ detector ] =
new TH1F( name, name, 2 * eTofConst::nStrips, 0, 2 * eTofConst::nStrips );
578 unsigned int strip = ( key % 1000 ) / 10;
579 unsigned int side = key % 10;
582 LOG_DEBUG << i <<
" " << detector <<
" " << strip <<
" " << side <<
" " << digiTimeCorrTable->timeCorr[ i ] << endm;
585 mDigiTimeCorr.at( detector )->SetBinContent( strip + eTofConst::nStrips * ( side - 1 ) , digiTimeCorrTable->timeCorr[ i ] );
588 for(
auto& kv : mDigiTimeCorr ) {
589 kv.second->SetDirectory( 0 );
596 LOG_INFO <<
"etofDigiSlewCorr: no filename provided --> load database table" << endm;
598 dbDataSet = GetDataBase(
"Calibrations/etof/etofDigiSlewCorr" );
600 St_etofDigiSlewCorr* etofDigiSlewCorr =
static_cast< St_etofDigiSlewCorr*
> ( dbDataSet->
Find(
"etofDigiSlewCorr" ) );
601 if( !etofDigiSlewCorr ) {
602 LOG_ERROR <<
"unable to get the digi slewing correction from the database" << endm;
606 etofDigiSlewCorr_st* digiSlewCorrTable = etofDigiSlewCorr->GetTable();
608 for(
size_t i=0; i<eTofConst::nChannelsInSystem; i++ ) {
609 unsigned int key = channelToKey( i );
612 std::vector< float > binEdges;
613 std::vector< float > corr;
615 binEdges.push_back( 0. );
616 for(
size_t j=0; j<etofSlewing::nTotBins; j++ ) {
617 int tableIndex = i * etofSlewing::nTotBins + j;
619 if( i != digiSlewCorrTable->channelId[ tableIndex ] ) {
620 LOG_ERROR <<
"something went wrong in reading the database table for eTOF slewing corrections" << endm;
624 binEdges.push_back( digiSlewCorrTable->upperTotEdge[ tableIndex ] * etofSlewing::conversionFactor );
625 corr.push_back( digiSlewCorrTable->corr[ tableIndex ] * etofSlewing::conversionFactor );
629 if( mDigiSlewCorr.count( key ) == 0 ) {
630 TString name = Form(
"digiSlewCorr_%d", key );
631 mDigiSlewCorr[ key ] =
new TProfile( name, name, etofSlewing::nTotBins, binEdges.data() );
635 for(
size_t j=0; j<etofSlewing::nTotBins; j++ ) {
636 float totCenter = mDigiSlewCorr.at( key )->GetBinCenter( j+1 );
637 mDigiSlewCorr.at( key )->Fill( totCenter, corr.at( j ), mMinDigisPerSlewBin + 1 );
641 for(
auto& kv : mDigiSlewCorr ) {
642 kv.second->SetDirectory( 0 );
646 LOG_INFO <<
"etof calibration histograms: filename provided --> use parameter file: " << mFileNameCalibHistograms.c_str() << endm;
648 if( !isFileExisting( mFileNameCalibHistograms ) ) {
649 LOG_ERROR <<
"unable to get the 'etofDigiTotCorr', 'etofDigiTimeCorr', 'etofDigiSlewCorr' parameters from file --> file does not exist" << endm;
652 TFile* histFile =
new TFile( mFileNameCalibHistograms.c_str(),
"READ" );
655 LOG_ERROR <<
"No calibration file found: " << mFileNameCalibHistograms.c_str() << endm;
656 LOG_INFO <<
"setting all parameters to default" << endm;
657 }
else if( histFile->IsZombie() ){
658 LOG_ERROR <<
"Zombie calibration file: " << mFileNameCalibHistograms.c_str() << endm;
659 LOG_INFO <<
"stopping execution" << endm;
663 TFile* histOffsetFile =
new TFile( mFileNameOffsetHistograms.c_str(),
"READ" );
665 if( !histOffsetFile ) {
666 LOG_INFO <<
"No offset file found: " << mFileNameOffsetHistograms.c_str() << endm;
667 LOG_INFO <<
"setting all parameters to default" << endm;
668 }
else if( histOffsetFile->IsZombie() ) {
669 LOG_ERROR <<
"Zombie offset file: " << mFileNameOffsetHistograms.c_str() << endm;
670 LOG_INFO <<
"stopping execution" << endm;
673 LOG_INFO <<
"Successfully opened RunOffset file "<< mFileNameOffsetHistograms.c_str() << endm;
678 TString hPosOffsetName = Form(
"calib_Run%d_PosOffsets_pfx", runnumber );
679 TString hT0OffsetName = Form(
"calib_Run%d_T0Offsets_pfx", runnumber );
680 TProfile* hPosOffsetProfile =
nullptr;
681 TProfile* hT0OffsetProfile =
nullptr;
683 if( histOffsetFile && !(histOffsetFile->IsZombie()) ){
684 LOG_INFO <<
"Getting run offset histograms Pos: "<< hPosOffsetName <<
" T0: "<< hT0OffsetName << endm;
685 hPosOffsetProfile = ( TProfile* ) histOffsetFile->Get( hPosOffsetName );
686 hT0OffsetProfile = ( TProfile* ) histOffsetFile->Get( hT0OffsetName );
689 for(
unsigned int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
691 if( mRunYear == 2018 && sector != 18 )
continue;
693 for(
unsigned int zPlane = eTofConst::zPlaneStart; zPlane <= eTofConst::zPlaneStop; zPlane++ ) {
694 for(
unsigned int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
696 unsigned int key = sector * 100 + zPlane * 10 + counter;
698 LOG_DEBUG <<
"detectorId key: " << sector <<
" " << zPlane <<
" " << counter << endm;
707 if( mDigiTotCorr.count( key ) == 0 ) {
708 TString name = Form(
"digiTotCorr_%d", key );
709 mDigiTotCorr[ key ] =
new TH1F( name, name, 2 * eTofConst::nStrips, 0, 2 * eTofConst::nStrips );
712 hname = Form(
"calib_Sector%02d_ZPlane%d_Det%d_TotDigi_pfx", sector, zPlane, counter );
713 hProfile = ( TProfile* ) histFile->Get( hname );
716 for(
size_t i=1; i<=2 * eTofConst::nStrips; i++ ) {
717 if( hProfile->GetBinContent( i ) != 0 ) {
718 mDigiTotCorr.at( key )->SetBinContent( i , hProfile->GetBinContent( i ) );
721 mDigiTotCorr.at( key )->SetBinContent( i , 1. );
725 if( mDigiTotCorr.at( key )->GetBinContent( i ) < 0.05 || mDigiTotCorr.at( key )->GetBinContent( i ) > 10 ) {
726 mDigiTotCorr.at( key )->SetBinContent( i , 1. );
731 if( isFileExisting( mFileNameCalibHistograms ) ) {
732 LOG_WARN <<
"unable to find histogram: " << hname << endm;
735 for(
size_t i=1; i<=2 * eTofConst::nStrips; i++ ) {
736 mDigiTotCorr.at( key )->SetBinContent( i , 1. );
740 LOG_DEBUG <<
"histogram " << mDigiTotCorr.at( key )->GetName() <<
" filled" << endm;
746 if( mDigiTimeCorr.count( key ) == 0 ) {
747 TString name = Form(
"digiTimeCorr_%d", key );
748 mDigiTimeCorr[ key ] =
new TH1F( name, name, 2 * eTofConst::nStrips, 0, 2 * eTofConst::nStrips );
752 hname = Form(
"calib_Sector%02d_ZPlane%d_Det%d_Pos_pfx", sector, zPlane, counter );
753 hProfile = ( TProfile* ) histFile->Get( hname );
755 double dRunOffset = 0;
756 if (hPosOffsetProfile) {
757 int mCounterBin = hPosOffsetProfile->FindBin( 9*(sector -13) + 3 * (zPlane - 1) + counter );
758 dRunOffset = hPosOffsetProfile->GetBinContent( mCounterBin );
759 LOG_DEBUG <<
"setting run position offset to "<< dRunOffset<<
" for counter "<< ( 9*(sector -13) + 3 * (zPlane - 1) + counter ) << endm;
761 LOG_INFO <<
"position offset histogram "<<hPosOffsetName <<
" not found" << endm;
765 for(
size_t i=1; i<= eTofConst::nStrips; i++ ) {
766 mDigiTimeCorr.at( key )->AddBinContent( i , -1. * ( hProfile->GetBinContent( i ) + dRunOffset ) / mSignalVelocity.at( key ) );
767 mDigiTimeCorr.at( key )->AddBinContent( eTofConst::nStrips + i , ( hProfile->GetBinContent( i ) + dRunOffset ) / mSignalVelocity.at( key ) );
771 if( isFileExisting( mFileNameCalibHistograms ) ) {
772 LOG_WARN <<
"unable to find histogram: " << hname << endm;
777 hname = Form(
"calib_Sector%02d_ZPlane%d_Det%d_T0corr", sector, zPlane, counter );
778 hProfile = ( TProfile* ) histFile->Get( hname );
781 if (hT0OffsetProfile) {
782 int mCounterBin = hT0OffsetProfile->FindBin( 9*(sector -13) + 3 * (zPlane - 1) + counter );
783 dRunOffset = hT0OffsetProfile->GetBinContent( mCounterBin );
785 LOG_DEBUG <<
"setting run time offset to "<< dRunOffset<<
" for counter "<< ( 9*(sector -13) + 3 * (zPlane - 1) + counter ) << endm;
787 if( hProfile && hProfile->GetNbinsX() == 1 ) {
788 LOG_DEBUG <<
"T0 histogram with 1 bin: " << key << endm;
789 for(
size_t i=1; i<=2 * eTofConst::nStrips; i++ ) {
790 mDigiTimeCorr.at( key )->AddBinContent( i , hProfile->GetBinContent( 1 ) + dRunOffset );
793 else if( hProfile && hProfile->GetNbinsX() == eTofConst::nStrips ) {
794 LOG_DEBUG <<
"T0 histogram with 32 bins: " << key << endm;
795 for(
size_t i=1; i<= eTofConst::nStrips; i++ ) {
796 mDigiTimeCorr.at( key )->AddBinContent( i , hProfile->GetBinContent( i ) + dRunOffset );
797 mDigiTimeCorr.at( key )->AddBinContent( i + eTofConst::nStrips , hProfile->GetBinContent( i ) + dRunOffset );
801 if( isFileExisting( mFileNameCalibHistograms ) ) {
802 LOG_WARN <<
"unable to find histogram: " << hname << endm;
806 LOG_DEBUG <<
"histogram " << mDigiTimeCorr.at( key )->GetName() <<
" filled" << endm;
812 for(
unsigned int chan = 0; chan < eTofConst::nChannelsPerCounter; chan++ ) {
813 unsigned int strip = ( chan % 32 ) + 1;
814 unsigned int side = ( chan / 32 ) + 1;
815 unsigned int key = sector * 100000 + zPlane * 10000 + counter * 1000 + strip * 10 + side;
817 LOG_DEBUG <<
"channelId key: " << sector <<
" " << zPlane <<
" " << counter <<
" " << strip <<
" " << side << endm;
819 hname = Form(
"calib_Sector%02d_ZPlane%d_Det%d_Chan%d_Walk_pfx", sector, zPlane, counter, chan );
820 hProfile = ( TProfile* ) histFile->Get( hname );
824 LOG_DEBUG <<
"unable to find histogram: " << hname <<
"--> check detector-wise" << endm;
825 hname = Form(
"calib_Sector%02d_ZPlane%d_Det%d_AvWalk_pfx", sector, zPlane, counter );
826 hProfile = ( TProfile* ) histFile->Get( hname );
830 unsigned int nbins = hProfile->GetNbinsX();
832 if( mDigiSlewCorr.count( key ) == 0 ) {
834 std::vector< float > bins( nbins + 1 );
836 for(
size_t i=0; i<nbins; i++ ) {
837 bins.at( i ) = hProfile->GetXaxis()->GetBinLowEdge( i+1 );
839 bins.at( nbins ) = hProfile->GetXaxis()->GetBinUpEdge( nbins );
841 TString name = Form(
"digiSlewCorr_%d", key );
842 mDigiSlewCorr[ key ] =
new TProfile( name, name, nbins, bins.data() );
845 for(
size_t iTotBin=1; iTotBin<=nbins; iTotBin++ ) {
846 mDigiSlewCorr.at( key )->Fill( hProfile->GetBinCenter( iTotBin ), hProfile->GetBinContent( iTotBin ), hProfile->GetBinEntries( iTotBin ) );
850 LOG_DEBUG <<
"unable to find histogram: " << hname << endm;
858 for(
auto& kv : mDigiTotCorr ) {
859 kv.second->SetDirectory( 0 );
861 for(
auto& kv : mDigiTimeCorr ) {
862 kv.second->SetDirectory( 0 );
864 for(
auto& kv : mDigiSlewCorr ) {
865 kv.second->SetDirectory( 0 );
878 if( mFileNameResetTimeCorr.empty() ) {
879 LOG_INFO <<
"etofResetTimeCorr: no filename provided --> load database table" << endm;
881 dbDataSet = GetDataBase(
"Calibrations/etof/etofResetTimeCorr" );
883 St_etofResetTimeCorr* etofResetTimeCorr =
static_cast< St_etofResetTimeCorr*
> ( dbDataSet->
Find(
"etofResetTimeCorr" ) );
884 if( !etofResetTimeCorr ) {
885 LOG_ERROR <<
"unable to get the reset time correction from the database" << endm;
889 etofResetTimeCorr_st* resetTimeCorrTable = etofResetTimeCorr->GetTable();
891 mResetTimeCorr = resetTimeCorrTable->resetTimeOffset;
894 LOG_INFO <<
"etofResetTimeCorr: filename provided --> use parameter file: " << mFileNameResetTimeCorr.c_str() << endm;
896 paramFile.open( mFileNameResetTimeCorr.c_str() );
898 if( !paramFile.is_open() ) {
899 LOG_ERROR <<
"unable to get the 'etofResetTimeCorr' parameters from file --> file does not exist" << endm;
903 std::map< unsigned int, float > param;
906 while( paramFile >> temp ) {
908 param[ (
unsigned int ) temp ] = temp2;
913 for(
const auto& kv : param ) {
914 LOG_DEBUG <<
"run: " << kv.first <<
" --> reset time corr = " << kv.second <<
" ns" << endm;
917 if( param.count( runnumber ) ) {
918 mResetTimeCorr = param.at( runnumber );
922 LOG_INFO <<
"additional reset time offset correction: " << mResetTimeCorr <<
" ns" << endm;
927 mPulserPeakTot.clear();
929 if( mFileNamePulserTotPeak.empty() ) {
930 LOG_INFO <<
"etofPulserPeakTot: no filename provided --> load database table" << endm;
932 dbDataSet = GetDataBase(
"Calibrations/etof/etofPulserTotPeak" );
934 St_etofPulserTotPeak* etofPulserTotPeak =
static_cast< St_etofPulserTotPeak*
> ( dbDataSet->
Find(
"etofPulserTotPeak" ) );
935 if( !etofPulserTotPeak ) {
936 LOG_ERROR <<
"unable to get the pulser tot peak parameters from the database" << endm;
940 etofPulserTotPeak_st* pulserTotTable = etofPulserTotPeak->GetTable();
942 for(
size_t i=0; i<eTofConst::nCountersInSystem * 2; i++ ) {
943 if( pulserTotTable->pulserTot[ i ] > 0 ) {
944 mPulserPeakTot[ sideToKey( i ) ] = ( int ) pulserTotTable->pulserTot[ i ];
949 LOG_INFO <<
"etofPulserPeakTot: filename provided --> use parameter file: " << mFileNamePulserTotPeak.c_str() << endm;
951 paramFile.open( mFileNamePulserTotPeak.c_str() );
953 if( !paramFile.is_open() ) {
954 LOG_ERROR <<
"unable to get the 'etofPulserTotPeak' parameters from file --> file does not exist" << endm;
958 std::vector< float > param;
960 while( paramFile >> temp ) {
961 param.push_back( temp );
966 if( param.size() != eTofConst::nCountersInSystem * 2 ) {
967 LOG_ERROR <<
"parameter file for 'etofPulserTotPeak' has not the right amount of entries: ";
968 LOG_ERROR << param.size() <<
" instead of " << eTofConst::nCountersInSystem * 2 <<
" !!!!" << endm;
972 for(
size_t i=0; i<eTofConst::nCountersInSystem * 2; i++ ) {
973 if( param.at( i ) > 0 ) {
974 mPulserPeakTot[ sideToKey( i ) ] = param.at( i );
979 for(
const auto& kv : mPulserPeakTot ) {
980 LOG_DEBUG <<
"side key: " << kv.first <<
" --> pulser peak tot = " << kv.second <<
" (bin)" << endm;
986 mPulserTimeDiffGbtx.clear();
988 if( mFileNamePulserTimeDiffGbtx.empty() ) {
989 LOG_INFO <<
"etofPulserTimeDiffGbtx: no filename provided --> load database table" << endm;
991 dbDataSet = GetDataBase(
"Calibrations/etof/etofPulserTimeDiffGbtx" );
993 St_etofPulserTimeDiffGbtx* etofPulserTimeDiffGbtx =
static_cast< St_etofPulserTimeDiffGbtx*
> ( dbDataSet->
Find(
"etofPulserTimeDiffGbtx" ) );
994 if( !etofPulserTimeDiffGbtx ) {
995 LOG_ERROR <<
"unable to get the pulser time difference parameters from the database" << endm;
999 etofPulserTimeDiffGbtx_st* pulserTimeTable = etofPulserTimeDiffGbtx->GetTable();
1001 for(
size_t i=0; i<eTofConst::nModules * eTofConst::nSides; i++ ) {
1002 unsigned int sector = eTofConst::sectorStart + i / ( eTofConst::nPlanes * eTofConst::nSides );
1003 unsigned int zPlane = eTofConst::zPlaneStart + ( i % ( eTofConst::nPlanes * eTofConst::nSides ) ) / eTofConst::nSides;
1004 unsigned int side = eTofConst::counterStart + i % eTofConst::nSides;
1006 mPulserTimeDiffGbtx[ sector * 1000 + zPlane * 100 + 1 * 10 + side ] = 0.;
1007 mPulserTimeDiffGbtx[ sector * 1000 + zPlane * 100 + 2 * 10 + side ] = pulserTimeTable->pulserTimeDiffGbtx[ i * 2 + 0 ];
1008 mPulserTimeDiffGbtx[ sector * 1000 + zPlane * 100 + 3 * 10 + side ] = pulserTimeTable->pulserTimeDiffGbtx[ i * 2 + 1 ];
1012 LOG_INFO <<
"etofPulserTimeDiff: filename provided --> use parameter file: " << mFileNamePulserTimeDiffGbtx.c_str() << endm;
1014 paramFile.open( mFileNamePulserTimeDiffGbtx.c_str() );
1016 if( !paramFile.is_open() ) {
1017 LOG_ERROR <<
"unable to get the 'etotPulserTimeDiffGbtc' parameters from file --> file does not exist" << endm;
1021 std::vector< float > param;
1023 while( paramFile >> temp ) {
1024 param.push_back( temp );
1029 if( param.size() != eTofConst::nModules * eTofConst::nSides * 2 ) {
1030 LOG_ERROR <<
"parameter file for 'etofPulserTimeDiffGbtx' has not the right amount of entries: ";
1031 LOG_ERROR << param.size() <<
" instead of " << eTofConst::nModules * eTofConst::nSides <<
" !!!!" << endm;
1035 for(
size_t i=0; i<eTofConst::nModules * eTofConst::nSides; i++ ) {
1036 unsigned int sector = eTofConst::sectorStart + i / ( eTofConst::nPlanes * eTofConst::nSides );
1037 unsigned int zPlane = eTofConst::zPlaneStart + ( i % ( eTofConst::nPlanes * eTofConst::nSides ) ) / eTofConst::nSides;
1038 unsigned int side = eTofConst::counterStart + i % eTofConst::nSides;
1040 mPulserTimeDiffGbtx[ sector * 1000 + zPlane * 100 + 1 * 10 + side ] = 0.;
1041 mPulserTimeDiffGbtx[ sector * 1000 + zPlane * 100 + 2 * 10 + side ] = param.at( i * 2 + 0 );
1042 mPulserTimeDiffGbtx[ sector * 1000 + zPlane * 100 + 3 * 10 + side ] = param.at( i * 2 + 1 );
1048 bool allZero =
true;
1050 for(
const auto& kv : mPulserTimeDiffGbtx ) {
1051 if( fabs( kv.second ) > 1e-4 ) allZero =
false;
1054 LOG_INFO <<
"side key: " << kv.first <<
" --> pulser time diff inside Gbtx ( to counter 1 ) = " << kv.second << endm;
1059 mUsePulserGbtxDiff =
false;
1060 LOG_INFO <<
"the use of pulser relations inside a Gbtx is turned off" << endm;
1064 mHistograms.at(
"pulserDigiTimeDiff_GbtxCorrProfMod" )->Reset();
1075 StETofCalibMaker::FinishRun( Int_t runnumber )
1083 for(
auto kv = mDigiTotCorr.begin(); kv != mDigiTotCorr.end(); kv++ ) {
1085 kv->second =
nullptr;
1087 mDigiTotCorr.clear();
1089 for(
auto kv = mDigiTimeCorr.begin(); kv != mDigiTimeCorr.end(); kv++ ) {
1091 kv->second =
nullptr;
1093 mDigiTimeCorr.clear();
1095 for(
auto kv = mDigiSlewCorr.begin(); kv != mDigiSlewCorr.end(); kv++ ) {
1097 kv->second =
nullptr;
1099 mDigiSlewCorr.clear();
1101 mPulserPeakTot.clear();
1102 mPulserTimeDiff.clear();
1104 mJumpingPulsers.clear();
1106 mGet4StateMap.clear();
1107 mGet4ZeroStateMap.clear();
1108 mMasterStartVec.clear();
1120 LOG_INFO <<
"Finish() - writing *.etofCalib.root ..." << endm;
1132 LOG_DEBUG <<
"StETofCalibMaker::Make(): starting ..." << endm;
1134 mEvent = (
StEvent* ) GetInputDS(
"StEvent" );
1139 unsigned long int evtNr = GetEventNumber();
1140 if(mFileNameGet4State.empty()){
1143 if( evtNr > mDbEntryStop || evtNr < mDbEntryStart) readGet4State(mGlobalCounter , 99);
1148 while( evtNr > mDbEntryStop || evtNr < mDbEntryStart){
1152 LOG_ERROR <<
" Get4 State File for event Nr:" << GetEventNumber() <<
"not found" << endm;
1157 if(evtNr < mDbEntryStart) forward = -1;
1158 readGet4State(mGlobalCounter , forward);
1163 checkGet4State( evtNr );
1167 LOG_DEBUG <<
"Make(): running on StEvent" << endm;
1171 if( !etofCollection ) {
1172 LOG_WARN <<
"Make() - Found StEvent data structure, but no eTOF collection. Try MuDst processing instead" << endm;
1173 mMuDst = (
StMuDst* ) GetInputDS(
"MuDst" );
1176 LOG_DEBUG <<
"Make() - running on MuDsts" << endm;
1189 LOG_DEBUG <<
"Make(): no StEvent found" << endm;
1191 mMuDst = (
StMuDst* ) GetInputDS(
"MuDst" );
1194 LOG_DEBUG <<
"Make(): running on MuDsts" << endm;
1201 LOG_WARN <<
"Make() - no StMuDst or StEvent" << endm;
1215 if( !etofCollection ) {
1216 LOG_WARN <<
"processStEvent() - no etof collection" << endm;
1220 if( !etofCollection->digisPresent() ) {
1221 LOG_WARN <<
"processStEvent() - no digis present" << endm;
1225 if( !etofCollection->etofHeader() ) {
1226 LOG_WARN <<
"processStEvent() - no header" << endm;
1232 StETofHeader* etofHeader = etofCollection->etofHeader();
1233 StSPtrVecETofDigi& etofDigis = etofCollection->etofDigis();
1250 size_t nDigis = etofDigis.size();
1252 LOG_INFO <<
"processStEvent() - # fired eTOF digis : " << nDigis << endm;
1255 mTriggerTime = triggerTime( etofHeader );
1256 mResetTime = fmod( resetTime( etofHeader ), eTofConst::bTofClockCycle );
1258 std::map< unsigned int, std::vector< unsigned int > > pulserCandMap;
1261 for(
size_t i=0; i<nDigis; i++ ) {
1266 LOG_WARN <<
"No digi found" << endm;
1271 resetToRaw( aDigi );
1276 applyMapping( aDigi );
1279 if( mRunYear != 2018 ) {
1280 flagPulserDigis( aDigi, i, pulserCandMap );
1286 LOG_INFO <<
"size of pulserCandMap: " << pulserCandMap.size() << endm;
1288 calculatePulserOffsets( pulserCandMap );
1291 TClass* headerClass = etofHeader->IsA();
1292 if( headerClass->GetClassVersion() > 2 ){
1294 std::vector<bool> goodEventFlagVec;
1295 std::vector<bool> hasPulsersVec;
1298 for(
unsigned int iCounter = 0; iCounter < 108; iCounter++){
1299 hasPulsersVec.push_back((mNPulsersCounter.count(iCounter) > 0) && (mNPulsersCounter[iCounter] == 2));
1301 if (hasPulsersVec.size() == 108){
1306 for(
unsigned int iGet4 = 0; iGet4 < 1728; iGet4++){
1310 if (goodEventFlagVec.size() == 1728){
1311 etofHeader->setGoodEventFlagVec(goodEventFlagVec);
1319 int nDuplicates = 0;
1321 for(
size_t i=0; i<nDigis; i++ ) {
1325 LOG_WARN <<
"No digi found" << endm;
1330 current.tot = aDigi->
rawTot();
1331 current.time = aDigi->
rawTime();
1334 auto it = std::find( mStuckFwDigi.begin(), mStuckFwDigi.end(), current );
1335 if( it != mStuckFwDigi.end() ) {
1337 LOG_INFO <<
"digi from stuck firmware (s" << aDigi->
sector() <<
" m" << aDigi->
zPlane() <<
" c" << aDigi->
counter() <<
") --> ignore" << endm;
1343 else if( current == prev ) {
1344 mStuckFwDigi.push_back( current );
1345 resetToRaw( mMuDst->
etofDigi( i-1 ) );
1357 applyCalibration( aDigi, etofHeader );
1360 if( mDoQA && nDuplicates > 0 ) {
1361 LOG_INFO <<
"*** # duplicate digis from stuck firmware: " << nDuplicates << endm;
1362 for(
const auto& v : mStuckFwDigi ) {
1363 LOG_INFO <<
"stuck channel with geomId: " << v.geomId <<
" " << v.tot <<
" " << v.time << endm;
1366 mStuckFwDigi.clear();
1374 LOG_DEBUG <<
"processMuDst(): starting ..." << endm;
1377 if( !mMuDst->
etofArray( muETofDigi ) ) {
1378 LOG_WARN <<
"processMuDst() - no digi array" << endm;
1382 if( !mMuDst->numberOfETofDigi() ) {
1383 LOG_WARN <<
"processMuDst() - no digis present" << endm;
1387 if( !mMuDst->
etofArray( muETofHeader ) ) {
1388 LOG_WARN <<
"processMuDst() - no digi array" << endm;
1393 mNPulsersCounter.clear();
1412 size_t nDigis = mMuDst->numberOfETofDigi();
1415 mTriggerTime = triggerTime( (
StETofHeader* ) etofHeader );
1416 mResetTime = fmod( resetTime( (
StETofHeader* ) etofHeader ), eTofConst::bTofClockCycle );
1417 std::map< unsigned int, std::vector< unsigned int >> pulserCandMap;
1421 for(
size_t i=0; i<nDigis; i++ ) {
1426 LOG_WARN <<
"No digi found" << endm;
1431 resetToRaw( aDigi );
1437 applyMapping( aDigi );
1443 if( mRunYear != 2018 ) {
1444 flagPulserDigis( aDigi, i, pulserCandMap );
1451 calculatePulserOffsets( pulserCandMap );
1455 TClass* headerClass = etofHeader->IsA();
1456 if( headerClass->GetClassVersion() > 2 ){
1458 std::vector<bool> goodEventFlagVec;
1459 std::vector<bool> hasPulsersVec;
1462 for(
unsigned int iCounter = 0; iCounter < 108; iCounter++){
1463 hasPulsersVec.push_back((mNPulsersCounter.count(iCounter) > 0) && (mNPulsersCounter[iCounter] == 2));
1466 if (hasPulsersVec.size() == 108){
1467 etofHeader->setHasPulsersVec(hasPulsersVec);
1471 for(
unsigned int iGet4 = 0; iGet4 < 1728; iGet4++){
1475 if(mGet4StateMap[iGet4] == 3){
1476 goodEventFlagVec.at(iGet4) =
false;
1480 if (goodEventFlagVec.size() == 1728){
1481 etofHeader->setGoodEventFlagVec(goodEventFlagVec);
1488 int nDuplicates = 0;
1490 for(
size_t i=0; i<nDigis; i++ ) {
1494 LOG_WARN <<
"No digi found" << endm;
1499 current.tot = aDigi->
rawTot();
1500 current.time = aDigi->
rawTime();
1503 auto it = std::find( mStuckFwDigi.begin(), mStuckFwDigi.end(), current );
1504 if( it != mStuckFwDigi.end() ) {
1506 LOG_INFO <<
"digi from stuck firmware (s" << aDigi->
sector() <<
" m" << aDigi->
zPlane() <<
" c" << aDigi->
counter() <<
") --> ignore" << endm;
1512 else if( current == prev ) {
1513 mStuckFwDigi.push_back( current );
1514 resetToRaw( mMuDst->
etofDigi( i-1 ) );
1525 applyCalibration( aDigi, etofHeader );
1528 if( mDoQA && nDuplicates > 0 ) {
1529 LOG_INFO <<
"*** # duplicate digis from stuck firmware: " << nDuplicates << endm;
1530 for(
const auto& v : mStuckFwDigi ) {
1531 LOG_INFO <<
"stuck channel with geomId: " << v.geomId <<
" " << v.tot <<
" " << v.time << endm;
1534 mStuckFwDigi.clear();
1541 StETofCalibMaker::isFileExisting(
const std::string fileName )
1543 std::ifstream infile( fileName );
1544 return infile.good();
1553 StETofCalibMaker::resetToRaw(
StETofDigi* aDigi )
1555 if( !aDigi )
return;
1558 aDigi->setCalibTime( 0. );
1559 aDigi->setCalibTot( -1. );
1561 aDigi->setAssociatedHit(
nullptr );
1570 StETofCalibMaker::applyMapping(
StETofDigi* aDigi )
1572 std::vector< unsigned int > geomVec;
1574 unsigned int rocId = aDigi->
rocId();
1575 unsigned int get4Id = aDigi->
get4Id();
1576 unsigned int elChan = aDigi->
elChan();
1578 mHwMap->mapToGeom( rocId, get4Id, elChan, geomVec );
1580 if( geomVec.size() < 5 ) {
1582 LOG_ERROR <<
"geometry vector has wrong size !!! --> skip digi" << endm;
1587 unsigned int sector = geomVec.at( 0 );
1588 unsigned int zplane = geomVec.at( 1 );
1589 unsigned int counter = geomVec.at( 2 );
1590 unsigned int strip = geomVec.at( 3 );
1591 unsigned int side = geomVec.at( 4 );
1593 if( mDebug && ( sector == 0 || zplane == 0 || counter == 0 || strip == 0 || side == 0 ) ) {
1594 LOG_ERROR <<
"geometry vector has entries equal to zero !!! --> skip digi" << endm;
1597 aDigi->
setGeoAddress( sector, zplane, counter, strip, side );
1601 LOG_DEBUG <<
"sector, zplane, counter, strip, side: " << aDigi->
sector() <<
", ";
1602 LOG_DEBUG << aDigi->
zPlane() <<
", " << aDigi->
counter() <<
", ";
1603 LOG_DEBUG << aDigi->
strip() <<
", " << aDigi->
side() << endm;
1605 LOG_DEBUG <<
"continuous module number: " << mHwMap->module( aDigi->
sector(), aDigi->
zPlane() ) << endm;
1615 StETofCalibMaker::flagPulserDigis(
StETofDigi* aDigi,
unsigned int index, std::map<
unsigned int, std::vector< unsigned int > >& pulserDigiMap )
1617 bool isPulserCand =
false;
1623 if( ( aDigi->
strip() == 1 && aDigi->
side() == 1 ) || ( aDigi->
strip() == 32 && aDigi->
side() == 2 ) ) {
1624 float timeToTrigger = aDigi->
rawTime() - mTriggerTime;
1627 float totToPeak = aDigi->
rawTot() - mPulserPeakTot.at( key );
1628 float totToHalfPeak = aDigi->
rawTot() - mPulserPeakTot.at( key ) * 0.5;
1630 isPulserCand = ( timeToTrigger > mPulserWindow.at( aDigi->
rocId() ).first &&
1631 timeToTrigger < mPulserWindow.at( aDigi->
rocId() ).second &&
1632 ( fabs( totToPeak ) < 25 || fabs( totToHalfPeak ) < 10 ) );
1636 if( isPulserCand ) {
1637 pulserDigiMap[ key ].push_back( index );
1650 StETofCalibMaker::calculatePulserOffsets( std::map<
unsigned int, std::vector< unsigned int > >& pulserDigiMap )
1653 for(
auto it=pulserDigiMap.begin(); it!=pulserDigiMap.end(); it++ ) {
1654 LOG_DEBUG <<
"channel: " << it->first <<
" nCandidates: " << it->second.size() << endm;
1658 if( mReferencePulserIndex == 0 ) {
1660 LOG_INFO <<
"reference pulser index is 0 --> pulser correction is turned off" << endm;
1666 LOG_INFO <<
"reference pulser index: " << mReferencePulserIndex << endm;
1669 std::map< int, double > pulserTimes;
1670 mNPulsersCounter.clear();
1671 mPulserPresent.clear();
1674 for(
auto it=pulserDigiMap.begin(); it!=pulserDigiMap.end(); it++ ) {
1675 if( it->second.size() == 0 ) {
1678 int sideIndex = it->first;
1680 double bestDiff = 100000;
1683 for(
size_t j=0; j<it->second.size(); j++ ) {
1684 double pulserTime = 0.;
1685 double pulserTot = 0.;
1687 pulserTime = mMuDst->
etofDigi( it->second.at( j ) )->rawTime();
1688 pulserTot = mMuDst->
etofDigi( it->second.at( j ) )->rawTot();
1689 }
else if( mEvent ) {
1690 pulserTime = ( mEvent->etofCollection()->etofDigis() )[ it->second.at( j ) ]->
rawTime();
1691 pulserTot = ( mEvent->etofCollection()->etofDigis() )[ it->second.at( j ) ]->rawTot();
1693 double timeToTrigger = pulserTime - mTriggerTime;
1694 double totToPeak = pulserTot - mPulserPeakTot.at( sideIndex );
1696 if( mDebug && it->second.size() > 1 ) {
1697 LOG_INFO << it->second.size() <<
" pulsers @ " << sideIndex <<
" : timeToTrigger: " << timeToTrigger <<
" tot: " << pulserTot << endm;
1701 double currentDiff = fabs( timeToTrigger - mPulserPeakTime ) * 0.1 + fabs( totToPeak );
1702 if( currentDiff < bestDiff ) {
1703 bestDiff = currentDiff;
1708 if( mDebug && it->second.size() > 1 ) {
1709 LOG_INFO <<
" --> selected CAND-INDEX: " << candIndex << endm;
1712 double pulserTime = 0.;
1715 pulserTime = mMuDst->
etofDigi( it->second.at( candIndex ) )->rawTime();
1718 mMuDst->
etofDigi( it->second.at( candIndex ) )->setCalibTot( -999. );
1719 }
else if( mEvent ) {
1720 pulserTime = ( mEvent->etofCollection()->etofDigis() )[ it->second.at( candIndex ) ]->
rawTime();
1723 mEvent->etofCollection()->etofDigis() [ it->second.at( candIndex ) ]->setCalibTot( -999. );
1726 pulserTimes[ sideIndex ] = pulserTime;
1728 int sector = sideIndex / 1000;
1729 int plane = ( sideIndex % 1000) / 100;
1730 int counter = ( sideIndex % 100) / 10;
1731 int key = 9 * ( sector - 13 ) + 3 * ( plane - 1 ) + ( counter - 1 );
1732 if( mNPulsersCounter.count( key ) ){
1733 mNPulsersCounter[key]++;
1735 mNPulsersCounter[key] = 1;
1738 mPulserPresent[ sideIndex ] =
true;
1741 double referenceTime = 0.;
1744 if( pulserTimes.count( mReferencePulserIndex ) ) {
1745 referenceTime = pulserTimes.at( mReferencePulserIndex );
1748 LOG_INFO <<
"preliminary reference time:" << referenceTime << endm;
1755 if( mUsePulserGbtxDiff ) {
1756 for(
int gbtxId = 0; gbtxId < eTofConst::nModules * eTofConst::nSides; gbtxId++ ) {
1757 int sector = eTofConst::sectorStart + gbtxId / ( eTofConst::nPlanes * eTofConst::nSides );
1758 int zPlane = eTofConst::zPlaneStart + ( gbtxId % ( eTofConst::nPlanes * eTofConst::nSides ) ) / eTofConst::nSides;
1759 int side = eTofConst::sideStart + gbtxId % eTofConst::nSides;
1761 int partialKey = sector * 1000 + zPlane * 100 + side;
1763 vector< double > times( eTofConst::nCounters );
1765 double average = 0.;
1768 for(
int counter = 1; counter <= eTofConst::nCounters; counter++ ) {
1769 int key = partialKey + 10 * counter;
1771 if( pulserTimes.count( key ) ) {
1773 if( pulserTimes.count( partialKey + 10 ) ) {
1774 mHistograms.at(
"pulserDigiTimeToCounter1" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, pulserTimes.at( partialKey + 10 ) - pulserTimes.at( key ) );
1776 if( pulserTimes.count( partialKey + 20 ) ) {
1777 mHistograms.at(
"pulserDigiTimeToCounter2" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, pulserTimes.at( partialKey + 20 ) - pulserTimes.at( key ) );
1779 if( pulserTimes.count( partialKey + 30 ) ) {
1780 mHistograms.at(
"pulserDigiTimeToCounter3" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, pulserTimes.at( partialKey + 30 ) - pulserTimes.at( key ) );
1784 times.at( counter - 1 ) = pulserTimes.at( key ) + mPulserTimeDiffGbtx.at( key );
1786 bool isNonSmearedPulser =
false;
1787 if( referenceTime != 0 ) {
1788 double dist = times.at( counter - 1 ) - referenceTime;
1789 double redDist = mHistograms.at(
"pulserDigiTimeDiff_GbtxCorrProfMod" )->GetBinContent( gbtxId * eTofConst::nCounters + counter );
1791 double modDist = fmod( dist - redDist, eTofConst::coarseClockCycle );
1792 modDist = modDist - eTofConst::coarseClockCycle * round( modDist / eTofConst::coarseClockCycle );
1795 if( redDist == 0 || fabs( modDist ) > 0.5 ) {
1796 if( redDist != 0 ) LOG_INFO <<
"too far away --> smeared pulser: " << key <<
"(" << gbtxId <<
"-" << counter <<
")" << endm;
1801 isNonSmearedPulser =
true;
1804 mHistograms.at(
"pulserDigiTimeDiff_GbtxCorrProf" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, dist );
1805 mHistograms.at(
"pulserDigiTimeDiff_GbtxCorrProfMod" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, redDist );
1808 mHistograms.at(
"pulserDigiTimeDiff_GbtxCorr" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, dist );
1809 mHistograms.at(
"pulserDigiTimeDiff" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, pulserTimes.at( key ) - referenceTime );
1814 if( isNonSmearedPulser ) {
1815 average += times.at( counter - 1 );
1819 times.at( counter - 1 ) = 0.;
1826 if( nAv == eTofConst::nCounters ) {
1827 double diff12 = fabs( times.at( 0 ) - times.at( 1 ) );
1828 double diff13 = fabs( times.at( 0 ) - times.at( 2 ) );
1829 double diff23 = fabs( times.at( 1 ) - times.at( 2 ) );
1831 if( diff12 > 0.2 && diff13 > 0.2 && diff23 < 0.2 ) {
1832 average -= times.at( 0 );
1835 if( fabs( times.at( 0 ) - ( average / nAv ) + eTofConst::coarseClockCycle ) < 0.2 ) {
1836 mJumpingPulsers[ partialKey + 10 ] = 1;
1838 times.at( 0 ) += eTofConst::coarseClockCycle;
1839 average += times.at( 0 );
1842 else if( fabs( times.at( 0 ) - ( average / nAv ) - eTofConst::coarseClockCycle ) < 0.2 ) {
1843 mJumpingPulsers[ partialKey + 10 ] = -1;
1845 times.at( 0 ) -= eTofConst::coarseClockCycle;
1846 average += times.at( 0 );
1851 mHistograms.at(
"1_off" )->Fill( gbtxId * eTofConst::nCounters + 1.5, times.at( 0 ) - ( average / nAv ) );
1854 else if( diff12 > 0.2 && diff13 < 0.2 && diff23 > 0.2 ) {
1855 average -= times.at( 1 );
1858 if( fabs( times.at( 1 ) - ( average / nAv ) + eTofConst::coarseClockCycle ) < 0.2 ) {
1859 mJumpingPulsers[ partialKey + 20 ] = 1;
1861 times.at( 1 ) += eTofConst::coarseClockCycle;
1862 average += times.at( 1 );
1865 else if( fabs( times.at( 1 ) - ( average / nAv ) - eTofConst::coarseClockCycle ) < 0.2 ) {
1866 mJumpingPulsers[ partialKey + 20 ] = -1;
1868 times.at( 1 ) -= eTofConst::coarseClockCycle;
1869 average += times.at( 1 );
1874 mHistograms.at(
"2_off" )->Fill( gbtxId * eTofConst::nCounters + 1.5, times.at( 1 ) - ( average / nAv ) );
1877 else if( diff12 < 0.2 && diff13 > 0.2 && diff23 > 0.2 ) {
1878 average -= times.at( 2 );
1881 if( fabs( times.at( 2 ) - ( average / nAv ) + eTofConst::coarseClockCycle ) < 0.2 ) {
1882 mJumpingPulsers[ partialKey + 30 ] = 1;
1884 times.at( 2 ) += eTofConst::coarseClockCycle;
1885 average += times.at( 2 );
1888 else if( fabs( times.at( 2 ) - ( average / nAv ) - eTofConst::coarseClockCycle ) < 0.2 ) {
1889 mJumpingPulsers[ partialKey + 30 ] = -1;
1891 times.at( 2 ) -= eTofConst::coarseClockCycle;
1892 average += times.at( 2 );
1897 mHistograms.at(
"3_off" )->Fill( gbtxId * eTofConst::nCounters + 1.5, times.at( 2 ) - ( average / nAv ) );
1902 if( nAv == eTofConst::nCounters - 1 ) {
1904 if( times.at( 0 ) > 0 && times.at( 1 ) > 0 && fabs( fabs( times.at( 0 ) - times.at( 1 ) ) - eTofConst::coarseClockCycle ) < 0.2 ) {
1905 if( mJumpingPulsers.count( partialKey + 10 ) ) {
1907 times.at( 0 ) += mJumpingPulsers.at( partialKey + 10 ) * eTofConst::coarseClockCycle;
1908 average += mJumpingPulsers.at( partialKey + 10 ) * eTofConst::coarseClockCycle;
1910 else if( mJumpingPulsers.count( partialKey + 20 ) ) {
1912 times.at( 1 ) += mJumpingPulsers.at( partialKey + 20 ) * eTofConst::coarseClockCycle;
1913 average += mJumpingPulsers.at( partialKey + 20 ) * eTofConst::coarseClockCycle;
1917 if( times.at( 0 ) < times.at( 1 ) ) {
1918 times.at( 0 ) += eTofConst::coarseClockCycle;
1919 average += eTofConst::coarseClockCycle;
1922 times.at( 1 ) += eTofConst::coarseClockCycle;
1923 average += eTofConst::coarseClockCycle;
1927 else if( times.at( 0 ) && times.at( 2 ) > 0 && fabs( fabs( times.at( 0 ) - times.at( 2 ) ) - eTofConst::coarseClockCycle ) < 0.2 ) {
1928 if( mJumpingPulsers.count( partialKey + 10 ) ) {
1930 times.at( 0 ) += mJumpingPulsers.at( partialKey + 10 ) * eTofConst::coarseClockCycle;
1931 average += mJumpingPulsers.at( partialKey + 10 ) * eTofConst::coarseClockCycle;
1933 else if( mJumpingPulsers.count( partialKey + 30 ) ) {
1935 times.at( 2 ) += mJumpingPulsers.at( partialKey + 30 ) * eTofConst::coarseClockCycle;
1936 average += mJumpingPulsers.at( partialKey + 30 ) * eTofConst::coarseClockCycle;
1940 if( times.at( 0 ) < times.at( 2 ) ) {
1941 times.at( 0 ) += eTofConst::coarseClockCycle;
1942 average += eTofConst::coarseClockCycle;
1945 times.at( 2 ) += eTofConst::coarseClockCycle;
1946 average += eTofConst::coarseClockCycle;
1950 else if( times.at( 1 ) > 0 && times.at( 2 ) > 0 && fabs( fabs( times.at( 1 ) - times.at( 2 ) ) - eTofConst::coarseClockCycle ) < 0.2 ) {
1951 if( mJumpingPulsers.count( partialKey + 20 ) ) {
1953 times.at( 1 ) += mJumpingPulsers.at( partialKey + 20 ) * eTofConst::coarseClockCycle;
1954 average += mJumpingPulsers.at( partialKey + 20 ) * eTofConst::coarseClockCycle;
1956 else if( mJumpingPulsers.count( partialKey + 30 ) ) {
1958 times.at( 2 ) += mJumpingPulsers.at( partialKey + 30 ) * eTofConst::coarseClockCycle;
1959 average += mJumpingPulsers.at( partialKey + 30 ) * eTofConst::coarseClockCycle;
1963 if( times.at( 1 ) < times.at( 2 ) ) {
1964 times.at( 1 ) += eTofConst::coarseClockCycle;
1965 average += eTofConst::coarseClockCycle;
1968 times.at( 2 ) += eTofConst::coarseClockCycle;
1969 average += eTofConst::coarseClockCycle;
1980 if( mDoQA && referenceTime != 0 ) {
1981 mHistograms.at(
"pulserDigiTimeDiff_perGbtx" )->Fill( gbtxId * eTofConst::nCounters + 1.5, average - referenceTime );
1984 for(
int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
1985 double diffToAv = 0.;
1987 if( times.at( counter - eTofConst::counterStart ) != 0. ) {
1988 diffToAv = times.at( counter - eTofConst::counterStart ) - average;
1990 if( fabs( diffToAv ) > 0.2 ) diffToAv = 0.;
1993 mHistograms.at(
"pulserDigiTimeDiff_toAverage" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, diffToAv );
1997 if( average != 0. ) {
1999 pulserTimes[ partialKey + 10 * counter ] = average + diffToAv - mPulserTimeDiffGbtx.at( partialKey + 10 * counter );
2003 if( pulserTimes.count( partialKey + 10 * counter ) ) {
2004 pulserTimes.erase( partialKey + 10 * counter );
2014 if( pulserTimes.count( mReferencePulserIndex ) ) {
2015 if( mPulserTimeDiff.count( mReferencePulserIndex ) ){
2016 referenceTime = pulserTimes.at( mReferencePulserIndex ) - mPulserTimeDiff[ mReferencePulserIndex ];
2019 referenceTime = pulserTimes.at( mReferencePulserIndex );
2026 if( referenceTime != 0 ) {
2027 int iLockThreshold = 0;
2028 mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->Reset(
"ICESM");
2030 for(
auto& kv : pulserTimes ) {
2032 if( mPulserTimeDiff.count( kv.first ) ) {
2036 double modDist = mPulserTimeDiff.at( kv.first ) - ( kv.second - referenceTime );
2040 if( fabs( modDist ) > 0.2 ) {
2041 mUnlockPulserState[ kv.first ]++;
2047 if( mUnlockPulserState.at( kv.first ) < iLockThreshold ) {
2056 mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->Fill( kv.second - referenceTime );
2060 if( mUnlockPulserState.count( kv.first ) ) {
2061 LOG_INFO <<
" --> new event doesn't have offset for pulser " << kv.first <<
" --> remove the entry" << endm;
2062 mUnlockPulserState.erase( kv.first );
2070 int sector = kv.first / 1000;
2071 int zPlane = ( kv.first % 1000 ) / 100;
2072 int counter = ( kv.first % 100 ) / 10;
2073 int side = kv.first % 10;
2075 int gbtxId = ( sector - eTofConst::sectorStart ) * ( eTofConst::nPlanes * eTofConst::nSides )
2076 + ( zPlane - eTofConst::zPlaneStart ) * eTofConst::nSides
2077 + ( side - eTofConst::sideStart );
2079 if( mPulserTimeDiff.count( kv.first ) ) {
2080 mHistograms.at(
"pulserDigiTimeDiff_fullCorr" )->Fill( gbtxId * eTofConst::nCounters + counter - 0.5, mPulserTimeDiff.at( kv.first ) );
2083 mHistograms[
"pulserDigiPresence" ]->Fill(gbtxId * eTofConst::nCounters + counter - 0.5);
2089 mHistograms[
"pulserDigiPresence" ]->Fill( -1 );
2090 mHistograms[
"pulserDigiTimeDiff_CorrAgreement" ]->Fill( mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->GetMaximum() );
2091 mHistograms[
"pulserDigiTimeDiff_CorrCommonJump" ]->Fill( mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->GetEntries() );
2093 if( ( mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->GetEntries() > 150 ) && ( mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->GetMaximum() > 15 ) ){
2096 int iMaximumBin = mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->GetMaximumBin();
2097 double dRefCorrAverage = 0;
2098 int iNRefCorrAgree = 0;
2100 for(
auto& kv : pulserTimes ) {
2101 if ( mHistograms[
"pulserDigiTimeDiff_RefCorr" ]->FindBin(kv.second - referenceTime) == iMaximumBin ){
2102 dRefCorrAverage += kv.second - referenceTime;
2106 dRefCorrAverage /= iNRefCorrAgree;
2107 referenceTime -= dRefCorrAverage;
2109 mPulserTimeDiff[ mReferencePulserIndex ] -= dRefCorrAverage;
2113 for(
auto& kv : pulserTimes ) {
2114 if ( ! mPulserTimeDiff[ kv.first ] ) {
2115 mPulserTimeDiff[ kv.first ] = kv.second - referenceTime;
2118 if( mUnlockPulserState.count( kv.first ) ){
2119 if( mUnlockPulserState.at( kv.first ) > iLockThreshold ){
2120 mPulserTimeDiff[ kv.first ] = kv.second - referenceTime;
2137 if( !mStatus.count( key) || mStatus.at( key ) != 1 ) {
2139 LOG_DEBUG <<
"status of channel with key " << key <<
" was not ok ---> skip calibrating this digi" << endm;
2145 if( fabs( aDigi->
calibTot() + 999. ) < 1.e-5 ) {
2147 LOG_DEBUG <<
"digi flaged as pulser --> skip" << endm;
2152 float timeToTrigger = aDigi->
rawTime() - mTriggerTime;
2155 if( timeToTrigger > mTimingWindow.at( aDigi->
rocId() ).first &&
2156 timeToTrigger < mTimingWindow.at( aDigi->
rocId() ).second )
2159 if( mStrictPulserHandling ){
2161 if( !mPulserPresent.count( PulserKey ) ) {
2163 LOG_DEBUG <<
"no pulser in the same event for this counter --> digi skipped due to strict pulser handling" << endm;
2169 double calibTot = aDigi->
rawTot() * mGet4TotBinWidthNs * calibTotFactor( aDigi );
2171 aDigi->setCalibTot( calibTot );
2173 int get4Id = 144 * ( aDigi->
sector() - 13 ) + 48 * ( aDigi->
zPlane() -1 ) + 16 * ( aDigi->
counter() - 1 ) + 8 * ( aDigi->
side() - 1 ) + ( ( aDigi->
strip() - 1 ) / 4 );
2175 double stateCorr =0;
2176 if(mGet4StateMap[get4Id] == 1){
2178 }
else if(mGet4StateMap[get4Id] == 2){
2180 }
else if(mGet4StateMap[get4Id] == 3){
2182 }
else if(mGet4StateMap[get4Id] == 4){
2186 if(!mCalState) stateCorr = 0;
2189 double calibTime = aDigi->
rawTime() - mResetTime
2191 - calibTimeOffset( aDigi )
2192 - slewingTimeOffset( aDigi )
2193 - applyPulserOffset( aDigi )
2197 if(mGet4StateMap[get4Id] == 5){
2202 aDigi->setCalibTime( calibTime );
2206 LOG_DEBUG <<
"raw Time, ToT: " << aDigi->
rawTime() <<
", " << aDigi->
rawTot() << endm;
2207 LOG_DEBUG <<
"calibrated Time, ToT: " << aDigi->
calibTime() <<
", " << aDigi->
calibTot() << endm;
2213 LOG_DEBUG <<
"digi is outside the timing window (time to trigger = " << timeToTrigger <<
") --> skip" << endm;
2224 if( !aDigi )
return;
2227 aDigi->setCalibTime( 0. );
2228 aDigi->setCalibTot( -1. );
2230 aDigi->setAssociatedHitId( -1 );
2244 StETofCalibMaker::flagPulserDigis(
StMuETofDigi* aDigi,
unsigned int index, std::map<
unsigned int, std::vector< unsigned int > >& pulserDigiMap )
2246 flagPulserDigis( (
StETofDigi* ) aDigi, index, pulserDigiMap );
2264 StETofCalibMaker::calibTotFactor(
StETofDigi* aDigi )
2267 unsigned int bin = aDigi->
strip() + 32 * ( aDigi->
side() - 1 );
2269 if( mDigiTotCorr.count( key ) ) {
2270 float binContent = mDigiTotCorr.at( key )->GetBinContent( bin );
2272 if( fabs( binContent ) > 1e-5 ) {
2274 LOG_DEBUG <<
"calibTotFactor: histogram with key " << key <<
" at bin " << bin <<
" -> return bin content: " << binContent << endm;
2276 return (1.0/binContent);
2280 LOG_WARN <<
"calibTotFactor: histogram with key " << key <<
" at bin " << bin <<
" has content of 0 -> return 1" << endm;
2287 LOG_WARN <<
"calibTotFactor: required histogram with key " << key <<
" doesn't exist -> return 1" << endm;
2299 StETofCalibMaker::calibTimeOffset(
StETofDigi* aDigi )
2302 unsigned int bin = aDigi->
strip() + 32 * ( aDigi->
side() - 1 );
2304 if( mDigiTimeCorr.count( key ) ) {
2305 float binContent = mDigiTimeCorr.at( key )->GetBinContent( bin );
2307 LOG_DEBUG <<
"calibTimeOffset: histogram with key " << key <<
" at bin " << bin <<
" -> return bin content: " << binContent << endm;
2313 LOG_WARN <<
"calibTimeOffset: required histogram with key " << key <<
" doesn't exist -> return 0" << endm;
2325 StETofCalibMaker::slewingTimeOffset(
StETofDigi* aDigi )
2329 if( mDigiSlewCorr.count( key ) ) {
2331 unsigned int totBin = mDigiSlewCorr.at( key )->FindBin( aDigi->
rawTot() );
2333 if( mDigiSlewCorr.at( key )->GetBinEntries( totBin ) <= mMinDigisPerSlewBin && totBin < etofSlewing::nTotBins ) {
2335 LOG_DEBUG <<
"slewingTimeOffset: insufficient statistics for slewing calibration in channel " << key <<
" at tot bin " << totBin <<
" --> return 0" << endm;
2340 float val = mDigiSlewCorr.at( key )->Interpolate( aDigi->
rawTot() );
2342 LOG_DEBUG <<
"slewingTimeOffset: histogram with key " << key <<
" with calib TOT of " << aDigi->
calibTot() <<
" --> interpolated correction: " << val << endm;
2348 LOG_DEBUG <<
"slewingTimeOffset: required histogram with key " << key <<
" doesn't exist -> return 0" << endm;
2360 StETofCalibMaker::applyPulserOffset(
StETofDigi* aDigi )
2364 if( !mPulserTimeDiff.count( key )) {
2368 return mPulserTimeDiff.at( key );
2380 double triggerTime = header->trgGdpbFullTime();
2383 std::map< uint64_t, short > countsGdpbTs;
2384 for(
const auto& kv : header->rocGdpbTs() ) {
2386 LOG_DEBUG <<
"triggerTime (" << std::hex <<
"Ox" << kv.first << std::dec <<
") " << kv.second * eTofConst::coarseClockCycle * 1.e-9 << endm;
2388 ++countsGdpbTs[ kv.second ];
2395 uint64_t mostProbableTriggerTs = 0;
2397 for(
auto it = countsGdpbTs.begin(); it != countsGdpbTs.end(); it++ ) {
2398 auto next = std::next( it, 1 );
2399 auto prev = std::prev( it, 1 );
2401 short countTs = it->second;
2403 if( next != countsGdpbTs.end() && ( next->first - it->first ) == 1 ) {
2404 countTs += next->second;
2406 if( accCount > 0 && ( it->first - prev->first ) == 1 ) {
2407 countTs += prev->second;
2410 if( countTs >= accCount ) {
2413 if( it->second > maxCount ) {
2414 maxCount = it->second;
2415 mostProbableTriggerTs = it->first;
2420 if( mostProbableTriggerTs > 0 ) {
2421 triggerTime = mostProbableTriggerTs * eTofConst::coarseClockCycle;
2425 LOG_DEBUG <<
"trigger TS: " << mostProbableTriggerTs <<
" --> trigger time (ns): " << triggerTime << endm;
2440 std::map< uint64_t, short > countsStarTsRaw;
2441 for(
const auto& kv : header->rocStarTs() ) {
2443 LOG_DEBUG <<
"resetTime (" << std::hex <<
"Ox" << kv.first << std::dec <<
") " << kv.second * eTofConst::coarseClockCycle * 1.e-9 << endm;
2447 if( mRunYear == 2018 && kv.first != 0x18e6 )
continue;
2449 if( kv.second != 0 ) {
2450 ++countsStarTsRaw[ kv.second ];
2456 std::map< uint64_t, short > countsStarTs;
2457 for(
auto it = countsStarTsRaw.begin(); it != countsStarTsRaw.end(); it++ ) {
2458 auto next = std::next( it, 1 );
2460 short countTs = it->second;
2462 if( next != countsStarTsRaw.end() && ( next->first - it->first ) == 1 ) {
2463 countTs += next->second;
2466 countsStarTs[ it->first ] = countTs;
2473 if( countsStarTs.size() == 0 ) {
2474 LOG_INFO <<
"all AFCKs report a reset time value 0" << endm;
2477 for(
const auto& kv : countsStarTs ) {
2478 LOG_DEBUG <<
"resetTime cand:" << kv.first <<
" (" << kv.second <<
" times)" << endm;
2479 mHistograms.at(
"resetTimeCand_times" )->Fill( kv.second );
2482 for(
const auto& kv : header->rocStarTs() ) {
2483 unsigned int sector;
2484 mHwMap->mapToSector( kv.first, sector );
2486 LOG_DEBUG <<
"resetTime(" << sector <<
"): " << kv.second << endm;
2488 std::string histName =
"resetTimeDifferenceToSector" + to_string( sector );
2489 for(
const auto& jv : header->rocStarTs() ) {
2491 mHwMap->mapToSector( jv.first, sec );
2493 mHistograms.at( histName )->Fill( sec, ( int64_t ) jv.second - ( int64_t ) kv.second );
2499 while( countsStarTs.size() > 0 ) {
2500 auto it = std::max_element( countsStarTs.begin(), countsStarTs.end(),
2501 [](
const pair< uint64_t, short >& p1,
const pair< uint64_t, short >& p2 ) {
2502 return p1.second < p2.second; } );
2504 double resetTime = it->first * eTofConst::coarseClockCycle;
2508 if( abs( mResetTs - ( int64_t ) it->first ) < 2 ) {
2509 resetTime = mResetTs * eTofConst::coarseClockCycle;
2512 LOG_INFO <<
"change in reset TS: " << mResetTs <<
" --> " << it->first << endm;
2513 mResetTs = it->first;
2519 if( mTriggerTime - resetTime < 7.2e12 ) {
2521 LOG_DEBUG <<
"reset time (ns): " << resetTime <<
" --> difference to trigger time in seconds: " << ( mTriggerTime - resetTime ) * 1.e-9 << endm;
2523 LOG_DEBUG <<
"--> picked reset TS:" << mResetTs << endm;
2526 mHistograms.at(
"resetTimeCand_picked" )->Fill( it->second );
2528 auto rawIt = std::max_element( countsStarTsRaw.begin(), countsStarTsRaw.end(),
2529 [](
const pair< uint64_t, short >& p1,
const pair< uint64_t, short >& p2 ) {
2530 return p1.second < p2.second; } );
2532 mHistograms.at(
"resetTimeCand_compare" )->Fill( ( int64_t ) mResetTs - ( int64_t ) rawIt->first );
2533 mHistograms.at(
"resetTimeCand_value" )->Fill( mResetTs % (
int ) eTofConst::bTofClockCycle );
2539 countsStarTs.erase( it );
2549 StETofCalibMaker::channelToKey(
const unsigned int channelId ) {
2550 unsigned int sector = ( channelId / eTofConst::nChannelsPerSector ) + eTofConst::sectorStart;
2551 unsigned int zPlane = ( ( channelId % eTofConst::nChannelsPerSector ) / eTofConst::nChannelsPerModule ) + eTofConst::zPlaneStart;
2552 unsigned int counter = ( ( channelId % eTofConst::nChannelsPerModule ) / eTofConst::nChannelsPerCounter ) + eTofConst::counterStart;
2553 unsigned int strip = ( ( channelId % eTofConst::nChannelsPerCounter ) / eTofConst::nSides ) + eTofConst::stripStart;
2554 unsigned int side = ( channelId % eTofConst::nSides ) + eTofConst::sideStart;
2556 return sector * 100000 + zPlane * 10000 + counter * 1000 + strip * 10 + side;
2562 StETofCalibMaker::detectorToKey(
const unsigned int detectorId ) {
2563 unsigned int sector = ( detectorId / eTofConst::nCountersPerSector ) + eTofConst::sectorStart;
2564 unsigned int zPlane = ( ( detectorId % eTofConst::nCountersPerSector ) / eTofConst::nCounters ) + eTofConst::zPlaneStart;
2565 unsigned int counter = ( detectorId % eTofConst::nCounters ) + eTofConst::counterStart;
2567 return sector * 100 + zPlane * 10 + counter;
2573 StETofCalibMaker::sideToKey(
const unsigned int sideId ) {
2574 unsigned int sector = ( sideId / ( eTofConst::nCountersPerSector * eTofConst::nSides ) ) + eTofConst::sectorStart;
2575 unsigned int zPlane = ( ( sideId % ( eTofConst::nCountersPerSector * eTofConst::nSides ) ) / ( eTofConst::nCounters * eTofConst::nSides ) ) + eTofConst::zPlaneStart;
2576 unsigned int counter = ( ( sideId % ( eTofConst::nCounters * eTofConst::nSides ) ) / eTofConst::nSides ) + eTofConst::counterStart;
2577 unsigned int side = ( sideId % eTofConst::nSides ) + eTofConst::sideStart;
2579 return sector * 1000 + zPlane * 100 + counter * 10 + side;
2588 StETofCalibMaker::setHistFileName()
2590 string extension =
".etofCalib.root";
2592 if( GetChainOpt()->GetFileOut() !=
nullptr ) {
2593 TString outFile = GetChainOpt()->GetFileOut();
2595 mHistFileName = ( string ) outFile;
2598 size_t lastindex = mHistFileName.find_last_of(
"." );
2599 mHistFileName = mHistFileName.substr( 0, lastindex );
2602 lastindex = mHistFileName.find_last_of(
"." );
2603 mHistFileName = mHistFileName.substr( 0, lastindex );
2606 lastindex = mHistFileName.find_last_of(
"/" );
2607 mHistFileName = mHistFileName.substr( lastindex + 1, mHistFileName.length() );
2609 mHistFileName = mHistFileName + extension;
2611 LOG_ERROR <<
"Cannot set the output filename for histograms" << endm;
2617 StETofCalibMaker::bookHistograms()
2619 LOG_INFO <<
"bookHistograms() ... " << endm;
2621 mHistograms[
"pulserDigiTimeDiff_GbtxCorrProf" ] =
new TProfile(
"pulserDigiTimeDiff_GbtxCorrProf",
"time difference of pulsers to reference;pulser channel;#Delta T (ns)", 216, 0, 216,
"s" );
2622 mHistograms[
"pulserDigiTimeDiff_GbtxCorrProfMod" ] =
new TProfile(
"pulserDigiTimeDiff_GbtxCorrProfMod",
"time difference of pulsers to reference;pulser channel;#Delta T (ns)", 216, 0, 216,
"s" );
2623 mHistograms[
"pulserDigiTimeDiff_fullCorr" ] =
new TH2F(
"pulserDigiTimeDiff_fullCorr",
"time difference of pulsers to reference;pulser channel;#Delta T (ns)", 216, 0, 216, 360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2624 mHistograms[
"pulserDigiTimeDiff_RefCorr" ] =
new TH1F(
"pulserDigiTimeDiff_RefCorr",
"time difference of pulsers to reference; #Delta T (ns)", 45, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ));
2627 mHistograms[
"pulserDigiTimeDiff" ] =
new TH2F(
"pulserDigiTimeDiff",
"time difference of pulsers to reference;pulser channel;#Delta T (ns)", 216, 0, 216, 360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2628 mHistograms[
"pulserDigiTimeToCounter1" ] =
new TH2F(
"pulserDigiTimeToCounter1",
"time difference of pulsers to counter 1;pulser channel;#Delta T (ns)", 216, 0, 216, 2*360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2629 mHistograms[
"pulserDigiTimeToCounter2" ] =
new TH2F(
"pulserDigiTimeToCounter2",
"time difference of pulsers to counter 2;pulser channel;#Delta T (ns)", 216, 0, 216, 2*360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2630 mHistograms[
"pulserDigiTimeToCounter3" ] =
new TH2F(
"pulserDigiTimeToCounter3",
"time difference of pulsers to counter 3;pulser channel;#Delta T (ns)", 216, 0, 216, 2*360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2632 mHistograms[
"pulserDigiTimeDiff_GbtxCorr" ] =
new TH2F(
"pulserDigiTimeDiff_GbtxCorr",
"time difference of pulsers to reference;pulser channel;#Delta T (ns)", 216, 0, 216, 360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2633 mHistograms[
"pulserDigiTimeDiff_perGbtx" ] =
new TH2F(
"pulserDigiTimeDiff_perGbtx",
"average time difference of pulsers in one Gbtx to reference;pulser channel;#Delta T (ns)", 216/3, 0, 216, 360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2634 mHistograms[
"pulserDigiTimeDiff_toAverage" ] =
new TH2F(
"pulserDigiTimeDiff_toAverage",
"time difference of pulsers to reference;pulser channel;#Delta T (ns)", 216, 0, 216, 4*360, -359.5 * ( 6.25 / 112 ), 360.5 * ( 6.25 / 112 ) );
2636 mHistograms[
"1_off" ] =
new TH2F(
"1_off",
"average time difference of pulsers in one Gbtx to reference;pulser channel;#Delta T (ns)", 216/3, 0, 216, 360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2637 mHistograms[
"2_off" ] =
new TH2F(
"2_off",
"average time difference of pulsers in one Gbtx to reference;pulser channel;#Delta T (ns)", 216/3, 0, 216, 360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2638 mHistograms[
"3_off" ] =
new TH2F(
"3_off",
"average time difference of pulsers in one Gbtx to reference;pulser channel;#Delta T (ns)", 216/3, 0, 216, 360, -179.5 * ( 6.25 / 112 ), 180.5 * ( 6.25 / 112 ) );
2640 mHistograms[
"pulserDigiTimeDiff_CorrAgreement" ] =
new TH1F(
"pulserDigiTimeDiff_CorrAgreement",
"Number of pulsers agreeing on a common shift between events; #pulsers", 218, -0.5, 217.5);
2641 mHistograms[
"pulserDigiTimeDiff_CorrCommonJump" ] =
new TH1F(
"pulserDigiTimeDiff_CorrCommonJump",
"Number of pulsers jumping at the same time between events; #pulsers", 218, -0.5, 217.5);
2642 mHistograms[
"pulserDigiPresence" ] =
new TH1F(
"pulserDigiPresence",
"pulser presence (number of events at ( -1 );pulser channel", 218, -1.5, 216.5);
2644 for(
int i=0; i<12; i++ ) {
2645 std::string histName =
"resetTimeDifferenceToSector" + to_string( i + 13 );
2646 mHistograms[ histName ] =
new TH2F( Form(
"resetTimeDifferenceToSector%d", i + 13 ), Form(
"reset time difference to sector %d;sector;#DeltaT (clock ticks)", i + 13 ), 12, 12.5, 24.4, 5, -2.5, 2.5 );
2648 mHistograms[
"ETOF_QA_daqMissmatches_get4" ] =
new TProfile(
"ETOF_QA_daqMissmatches_get4",
"missmatch percentage for each get4; get4 []; missmatch percentage", 1728, 0.5, 1728.5 );
2649 mHistograms[
"ETOF_QA_daqMissmatches_counter" ] =
new TProfile(
"ETOF_QA_daqMissmatches_counter",
"missmatch percentage for each counter; counter []; missmatch percentage", 108, 0.5, 108.5 );
2650 mHistograms[
"resetTimeCand_times" ] =
new TH1F(
"resetTimeCand_times",
"sectors agreeing on reset time candidates;# sectors with common candidate;# events", 12, 0.5, 12.5 );
2651 mHistograms[
"resetTimeCand_picked" ] =
new TH1F(
"resetTimeCand_picked",
"sectors agreeing on picked reset time;# sectors with picked reset time;# events", 12, 0.5, 12.5 );
2652 mHistograms[
"resetTimeCand_compare" ] =
new TH1F(
"resetTimeCand_compare",
"difference between old and new way;#DeltaT (clock ticks);# events", 5, -2.5, 2.5 );
2653 mHistograms[
"resetTimeCand_value" ] =
new TH1F(
"resetTimeCand_value",
"picked reset time value;clock ticks;# events", (
int ) eTofConst::bTofClockCycle, 0.5, 0.5 + eTofConst::bTofClockCycle );
2656 for (
auto& kv : mHistograms ) {
2657 kv.second->SetDirectory( 0 );
2663 StETofCalibMaker::writeHistograms()
2665 if( mHistFileName !=
"" ) {
2666 LOG_INFO <<
"writing histograms to: " << mHistFileName.c_str() << endm;
2668 TFile histFile( mHistFileName.c_str(),
"RECREATE",
"etofCalib" );
2671 for(
int i=0; i<12; i++ ) {
2672 std::string histName =
"resetTimeDifferenceToSector" + to_string( i + 13 );
2673 mHistograms.at( histName )->Scale( 12. / mHistograms.at( histName )->GetEntries() );
2676 for (
const auto& kv : mHistograms ) {
2677 if( kv.second->GetEntries() > 0 ) kv.second->Write();
2683 LOG_INFO <<
"histogram file name is empty string --> cannot write histograms" << endm;
2689 void StETofCalibMaker::readGet4State(
int fileNr,
short forward){
2691 bool fileZero =
false;
2694 for(
int i =0; i< eTofConst::nGet4sInSystem; i++){
2695 mStateVec[i].clear();
2696 mStartVec[i].clear();
2697 mGet4StateMap[i] = 0;
2702 mMasterStartVec.clear();
2703 mMasterStartVec.resize(0);
2705 std::vector< unsigned long int > intVec;
2708 if(forward == 0) mGlobalCounter = 0;
2710 else if(forward > 0){ mGlobalCounter++;
2712 }
else {mGlobalCounter--;}
2714 if(mGlobalCounter == 0){
2719 if(mFileNameGet4State.empty()){
2721 TDataSet* dbDataSet = GetDataBase(
"Calibrations/etof/etofGet4State" );
2723 LOG_ERROR <<
"unable to get the get4 state map database" << endm;
2726 const int intsPerEntry = 1000000;
2728 St_etofGet4State* etofStateMap =
static_cast< St_etofGet4State*
> ( dbDataSet->
Find(
"etofGet4State" ) );
2729 if( !etofStateMap ) {
2730 LOG_ERROR <<
"unable to get the get4 state map from the database" << endm;
2734 etofGet4State_st* stateMapTable = etofStateMap->GetTable();
2736 for(
size_t i=0; i< intsPerEntry; i++ ) {
2737 if(stateMapTable->etofGet4State[ i ] <= 0)
break;
2738 intVec.push_back( stateMapTable->etofGet4State[ i ]);
2743 std::ifstream paramFile;
2745 paramFile.open( mFileNameGet4State.c_str() );
2747 if( !paramFile.is_open() ) {
2748 LOG_ERROR <<
"unable to get the 'Get4State' parameters from file --> file does not exist" << endm;
2752 unsigned long int temp;
2753 while( paramFile >> temp ) {
2754 intVec.push_back( temp );
2758 std::vector<unsigned long int> startVec;
2759 std::map<unsigned long int,vector<int>> stateVec;
2760 std::map<unsigned long int ,vector<int>> get4IdVec;
2762 decodeInt(intVec , startVec , stateVec , get4IdVec);
2765 for(
int i = 0; i< eTofConst::nGet4sInSystem;i++){
2767 for(
unsigned int j=0; j< startVec.size(); j++){
2769 unsigned long int key = startVec.at(j);
2771 for(
unsigned int n =0; n < get4IdVec.at(key).size(); n++){
2774 if(i == get4IdVec.at(key).at(n)){
2775 mStateVec[i].push_back(stateVec.at(key).at(n));
2776 mStartVec[i].push_back(startVec.at(j));
2783 mStateMapStart = 0 ;
2784 mStateMapStop = startVec.at(0);
2785 mDbEntryStart = startVec.at(0);
2786 mDbEntryStop = startVec.at((startVec.size()-1));
2791 mDbEntryStop = 99999999;
2794 sort( mMasterStartVec.begin(), mMasterStartVec.end() );
2795 mMasterStartVec.erase( unique( mMasterStartVec.begin(), mMasterStartVec.end() ), mMasterStartVec.end() );
2801 void StETofCalibMaker::checkGet4State(
unsigned long int eventNr){
2803 if(eventNr >= mStateMapStart && eventNr < mStateMapStop) {
2807 unsigned long int closestStop = 99999999;
2808 unsigned long int closestStart = 0;
2812 for(
unsigned int i =0; i< eTofConst::nGet4sInSystem; i++){
2814 std::vector<unsigned long int> tmpStart = mStartVec[i];
2815 std::vector<short> tmpState = mStateVec[i];
2818 unsigned int indexStart = 0;
2821 if (tmpStart.empty())
continue;
2823 auto lower = std::lower_bound(tmpStart.begin(), tmpStart.end(), eventNr);
2824 indexStart = std::distance(tmpStart.begin(), lower);
2825 if(indexStart > 0) indexStart--;
2828 if(eventNr > tmpStart.at((tmpStart.size() -1))){
2829 indexStart = (tmpStart.size() -1);
2833 if((indexStart < (tmpStart.size() -1 )) && eventNr == tmpStart.at(indexStart + 1)){
2838 newState = tmpState.at(indexStart);
2840 if(tmpStart.at(indexStart) > eventNr ) newState = mGet4ZeroStateMap[i];
2842 mGet4StateMap[i] = newState;
2847 for(
unsigned int z=0; z< mMasterStartVec.size();z++){
2851 closestStop = mMasterStartVec.at(z);
2853 }
else if(z == (mMasterStartVec.size()-1)){
2854 closestStart = mMasterStartVec.at(z);
2855 closestStop = 99999999;
2858 }
else if(eventNr == mMasterStartVec.at(z) ||
2859 (eventNr < mMasterStartVec.at(z+1) && eventNr > mMasterStartVec.at(z))){
2860 closestStart = mMasterStartVec.at(z);
2861 closestStop = mMasterStartVec.at(z+1);
2868 mStateMapStart = closestStart;
2869 mStateMapStop = closestStop;
2871 if(mStateMapStart == mDbEntryStop) {
2873 mStateMapStop = 99999999;
2878 void StETofCalibMaker::decodeInt( std::vector<unsigned long int>& intVec ,std::vector<unsigned long int>& startVec ,std::map<
unsigned long int,vector<int>>& stateVec ,std::map<
unsigned long int,vector<int>>& get4IdVec){
2880 unsigned long int lastEvtId =0;
2881 std::map<int, std::vector< stateStruct > > stateMap;
2884 for(
unsigned int i = 0; i < intVec.size(); i++){
2889 unsigned long int EvtId;
2895 stateStruct struct1;
2896 stateStruct struct2;
2898 switch (intVec.at(i) / 100000000) {
2903 tmp = intVec.at(i) % 3900000000;
2904 stateInt1 = tmp / 10000;
2905 stateInt2 = tmp % 10000;
2912 if(stateInt1 < 6912){
2913 Get4Id1 = stateInt1 % (eTofConst::nGet4sInSystem/2);
2914 get4state1 = stateInt1 / (eTofConst::nGet4sInSystem/2);
2916 if(stateInt2 < 6912){
2917 Get4Id2 = stateInt2 % (eTofConst::nGet4sInSystem/2);
2918 get4state2 = stateInt2 / (eTofConst::nGet4sInSystem/2);
2921 if(i < (eTofConst::nGet4sInSystem/4) ){
2922 mGet4DefaultStateMap[Get4Id1] = get4state1 + 1;
2923 mGet4DefaultStateMap[Get4Id2] = get4state2 + 1;
2930 tmp = intVec.at(i) % 4200000000;
2931 stateInt1 = tmp / 10000;
2932 stateInt2 = tmp % 10000;
2939 if(stateInt1 < 6912){
2940 Get4Id1 = stateInt1 % eTofConst::nGet4sInSystem;
2941 get4state1 = stateInt1 / eTofConst::nGet4sInSystem;
2943 if(stateInt2 < 6912){
2944 Get4Id2 = stateInt2 % eTofConst::nGet4sInSystem;
2945 get4state2 = stateInt2 / eTofConst::nGet4sInSystem;
2948 if(i >= (eTofConst::nGet4sInSystem/4) && i < ((eTofConst::nGet4sInSystem/4) + (eTofConst::nGet4sInSystem/2))){
2950 mGet4StateMap[Get4Id1] = get4state1;
2951 mGet4StateMap[Get4Id2] = get4state2;
2952 mGet4ZeroStateMap[Get4Id1] = get4state1;
2953 mGet4ZeroStateMap[Get4Id2] = get4state2;
2955 stateVec[lastEvtId].push_back(get4state1);
2956 get4IdVec[lastEvtId].push_back(Get4Id1);
2957 stateVec[lastEvtId].push_back(get4state2);
2958 get4IdVec[lastEvtId].push_back(Get4Id2);
2961 struct1.get4Id = Get4Id1;
2962 struct1.state = get4state1;
2963 struct1.evtId = lastEvtId;
2965 struct2.get4Id = Get4Id2;
2966 struct2.state = get4state2;
2967 struct2.evtId = lastEvtId;
2969 stateMap[Get4Id1].push_back(struct1);
2970 stateMap[Get4Id2].push_back(struct2);
2977 EvtId = intVec.at(i) % 4000000000;
2979 startVec.push_back(EvtId);
2980 mMasterStartVec.push_back(EvtId);
2989 tmp = intVec.at(i) % 4100000000;
2990 stateInt1 = tmp / 10000;
2994 if(stateInt1 < 6912) {
2995 Get4Id1 = stateInt1 % eTofConst::nGet4sInSystem;
2996 get4state1 = stateInt1 / eTofConst::nGet4sInSystem;
2999 stateVec[lastEvtId].push_back(get4state1);
3000 get4IdVec[lastEvtId].push_back(Get4Id1);
3003 struct1.get4Id = Get4Id1;
3004 struct1.state = get4state1;
3005 struct1.evtId = lastEvtId;
3007 stateMap[Get4Id1].push_back(struct1);
3012 LOG_ERROR <<
"Get4 state not well defined -> Check db / state file !" << endm;
3017 std::sort(startVec.begin(), startVec.end());
3018 std::sort(mMasterStartVec.begin(), mMasterStartVec.end());
3020 for(
unsigned int i=0; i< eTofConst::nGet4sInSystem;i++){
3022 std::vector<stateStruct> tmpVec = stateMap.at(i);
3024 for(
unsigned int j=0; j < stateMap.at(i).size();j++){
3025 tmpVec.push_back(stateMap.at(i).at(j));
3027 std::sort(tmpVec.begin(), tmpVec.end(), [] (stateStruct x, stateStruct y) {
return x.evtId < y.evtId; } );
3029 for(
unsigned int j=0; j< tmpVec.size();j++){
3031 stateVec[tmpVec.at(j).evtId].push_back(tmpVec.at(j).state);
3032 get4IdVec[tmpVec.at(j).evtId].push_back(tmpVec.at(j).get4Id);
unsigned int sector() const
Sector.
double calibTime() const
calibrated time
unsigned int zPlane() const
ZPlane.
static StMuETofHeader * etofHeader()
returns pointer to the StMuETofHeader
unsigned int side() const
Side.
unsigned int strip() const
Strip.
double rawTot() const
Getter for uncalibrated Tot.
unsigned int sector() const
Sector.
unsigned int zPlane() const
ZPlane.
unsigned int strip() const
Strip.
double rawTime() const
Raw Time.
double rawTot() const
Getter for uncalibrated Tot.
static TClonesArray * etofArray(int type)
returns pointer to the n-th TClonesArray from the etof arrays // FS
static StMuETofDigi * etofDigi(int i)
returns pointer to the i-th StMuEtofDigi
unsigned int elChan() const
electronic Channel.
unsigned int get4Id() const
get4Id.
unsigned int counter() const
Counter.
void setGeoAddress(const unsigned int iSector, const unsigned int iZPlane, const unsigned int iCounter, const unsigned int iChannel, const unsigned int iSide)
double calibTot() const
Getter for calibrated Tot.
unsigned int rocId() const
RocId.
unsigned int side() const
Side.
StETofCalibMaker(const char *name="etofCalib")
default constructor
unsigned int counter() const
Counter.
void setGeoAddress(const unsigned int iSector, const unsigned int iZPlane, const unsigned int iCounter, const unsigned int iChannel, const unsigned int iSide)
virtual TDataSet * Find(const char *path) const
double rawTime() const
Raw Time.