// ------------------------------------------------------------------ // ----- TTofTriglogScalUnpacker ----- // ----- Created 03/07/2013 by P.-A. Loizeau ----- // ----- Adapted from TTriglogProc.cxx by S. Linev ----- // ----- and TMbsCrateProc.cxx by P.-A. Loizeau ---- // ------------------------------------------------------------------ #include "TTofTriglogScalUnpacker.h" // TOF headers #include "TofDef.h" #include "TMbsUnpackTofPar.h" #include "TofTriglogDef.h" #include "TofScalerDef.h" #include "TTofTriglogBoard.h" #include "TTofScalerBoard.h" // FAIR headers #include "FairRootManager.h" #include "FairLogger.h" #include "TString.h" // ROOT headers #include "TClonesArray.h" #include "TH1.h" #include "TROOT.h" #include "TDirectory.h" #include "TString.h" TTofTriglogScalUnpacker::TTofTriglogScalUnpacker(): fParUnpack(0), fScalerBoardCollection(NULL), fuNbTriglogScal( 0 ), fuTrigOff( 0 ), fuTotalTriggerCount(), fuFirstMbsTime(), fuLastMbsTime(), fuFirstScaler(), fuLastScaler(), fhScalers(), fvuFirstScalers(), fdFirstMbsTime(), fdPrevMbsTime(), fdCurrMbsTime(), fuLastRefClk(), fhRefClkRate(), fhRefClkRateEvo(), fTriglogBoardCollection(NULL), fdEvoRangeUser(-1), fdEvoBinSzUser(-1), fhScalersCountsEvo() { } TTofTriglogScalUnpacker::TTofTriglogScalUnpacker( TMbsUnpackTofPar * parIn ): fParUnpack( parIn ), fScalerBoardCollection(NULL), fuNbTriglogScal( parIn->GetNbActiveBoards( tofMbs::triglogscal ) ), fuTrigOff( 0 ), fuTotalTriggerCount(), fuFirstMbsTime(), fuLastMbsTime(), fuFirstScaler(), fuLastScaler(), fhScalers(), fvuFirstScalers(), fdFirstMbsTime(), fdPrevMbsTime(), fdCurrMbsTime(), fuLastRefClk(), fhRefClkRate(), fhRefClkRateEvo(), fTriglogBoardCollection(NULL), fdEvoRangeUser(-1), fdEvoBinSzUser(-1), fhScalersCountsEvo() { // Some triglog board can be used as scaler board instead of trigger source if( 0 < fuNbTriglogScal ) { // Recover first the TRIGLOG and SCALER board objects created in general unpacker class FairRootManager* rootMgr = FairRootManager::Instance(); fScalerBoardCollection = (TClonesArray*) rootMgr->GetObject("TofRawScalers"); if(NULL == fScalerBoardCollection) { LOG(WARNING)<<"TTofTriglogScalUnpacker::TTofTriglogScalUnpacker : no Raw Scalers array! "<WithActiveTriglog() ) { fuTrigOff = 1; fTriglogBoardCollection = (TClonesArray*) rootMgr->GetObject("TofTriglog"); } // if( kTRUE == fParUnpack->WithActiveTriglog() ) // There may be some simple scaler boards fuTrigOff += parIn->GetNbActiveBoards( tofMbs::scaler2014 ); fuTrigOff += parIn->GetNbActiveBoards( tofMbs::orgen ); LOG(DEBUG)<<"TTofTriglogScalUnpacker::TTofTriglogScalUnpacker : Initialize objects for " << fuNbTriglogScal << " Triglog boards used as scaler "<ConstructedAt( uScalIndex + fuTrigOff); if( tofscaler::undef == fScalerBoard->GetScalerType() ) fScalerBoard->SetType( tofscaler::triglogscal ); } // for( UInt_t uScalIndex = 0; uScalIndex < fuNbTriglogScal; uScalIndex++) } // else of if(NULL == fScalerBoardCollection) fuTotalTriggerCount.resize(fuNbTriglogScal); fuFirstMbsTime.resize(fuNbTriglogScal); fuLastMbsTime.resize(fuNbTriglogScal); fuFirstScaler.resize(fuNbTriglogScal); fuLastScaler.resize(fuNbTriglogScal); fdFirstMbsTime.resize(fuNbTriglogScal); fdPrevMbsTime.resize(fuNbTriglogScal); fdCurrMbsTime.resize(fuNbTriglogScal); fuLastRefClk.resize(fuNbTriglogScal); for( UInt_t uScalIndex = 0; uScalIndex < fuNbTriglogScal; uScalIndex++) { // Initialize variable used in filling fdFirstMbsTime[uScalIndex] = 0; fdPrevMbsTime[uScalIndex] = -1; fdCurrMbsTime[uScalIndex] = -1; fuLastRefClk[uScalIndex] = 0; fuTotalTriggerCount[uScalIndex] = 0; fuFirstMbsTime[uScalIndex] = 0; fuLastMbsTime[uScalIndex] = 0; fuFirstScaler[uScalIndex].resize(triglog::kuNbScalers); fuLastScaler[uScalIndex].resize(triglog::kuNbScalers); for( UInt_t uScaler = 0; uScaler < triglog::kuNbScalers; uScaler++) { fuFirstScaler[uScalIndex][uScaler].resize(triglog::kuNbChan); fuLastScaler[uScalIndex][uScaler].resize(triglog::kuNbChan); } // for( UInt_t uScaler = 0; uScaler No TRIGLOG board active as scaler!!!!!" <<" recheck your VME address matrix "< No TRIGLOG board active as scaler!!!!!" <<" recheck your VME address matrix "<(iTrigScalIndex)) ) { LOG(ERROR)<<"Error TriglogScal number "<WithActiveTriglog() ) { // First check if ScalerBoard object for Triglog was created already // and check if ScalerBoard object for ScalOrMu14 were created already if( 1 + static_cast(fuTrigOff) + iTrigScalIndex <= fScalerBoardCollection->GetEntriesFast() ) fScalerBoard = (TTofScalerBoard*) fScalerBoardCollection->ConstructedAt( fuTrigOff + iTrigScalIndex, "C"); else for( Int_t iScalBd = fScalerBoardCollection->GetEntriesFast(); iScalBd <= static_cast(fuTrigOff) + iTrigScalIndex; iScalBd++ ) fScalerBoard = (TTofScalerBoard*) fScalerBoardCollection->ConstructedAt( iScalBd); } // if( kTRUE == fParUnpack->WithActiveTriglog() ) else fScalerBoard = (TTofScalerBoard*) fScalerBoardCollection->ConstructedAt( fuTrigOff + iTrigScalIndex, "C"); if( tofscaler::undef == fScalerBoard->GetScalerType() ) fScalerBoard->SetType( tofscaler::triglogscal ); UInt_t uIndx = 0; // Jump TRIGLOG not scaler data Int_t sync_num = pMbsData[uIndx]; // fTriglogBoard->SetSyncNb( sync_num ); uIndx++; LOG(DEBUG2)<<" ===================== TRIGLOG SCAL EVENT ============ " << sync_num % 0x1000000 <SetTriggPatt( (UInt_t) pMbsData[uIndx] ); uIndx++; // fTriglogBoard->SetMbsTimeSec( (UInt_t) pMbsData[uIndx] ); UInt_t uMbsTime = (UInt_t) pMbsData[uIndx]; uIndx++; LOG(DEBUG2)<<" TRIGLOG SCAL UNPACK test 0 "<< iTrigScalIndex <SetMbsTimeMilliSec( (UInt_t) pMbsData[uIndx] ); UInt_t uMbsTimeMs = (UInt_t) pMbsData[uIndx]; LOG(DEBUG2)<<" TRIGLOG SCAL UNPACK test 0a "<< iTrigScalIndex <SetScalerValue( uCh, uValue, uScaler ); } // for( UInt uCh = 0; uCh < triglog::kuNbChan; uCh++) { } // for( UInt uScaler = 0; uScaler < triglog::kuNbScalers; uScaler++) LOG(DEBUG2)<<" TRIGLOG SCAL UNPACK test 2"<SetInpPatt( pMbsData[uIndx] ); uIndx++; } // if( uIndx < uLength) if( uIndx < uLength) { // Reference clock is inside Tof MBS event only since October 2012 fScalerBoard->SetRefClk( pMbsData[uIndx] ); uIndx++; } // if( uIndx < uLength) LOG(DEBUG2)<<" TRIGLOG SCAL UNPACK finished"<SetPresentFlag( kTRUE ); UpdateStats( iTrigScalIndex, uMbsTime ); return; } void TTofTriglogScalUnpacker::UpdateStats( Int_t iTrigScalIndex, UInt_t uMbsTime ) { if( (iTrigScalIndex<0) || (fuNbTriglogScal <= static_cast(iTrigScalIndex)) ) { LOG(ERROR)<<"Error TriglogScal number "<At(fuTrigOff + iTrigScalIndex); if( NULL == fScalerBoard ) { LOG(ERROR)<<"TTofTriglogScalUnpacker::UpdateStats => Board objects not existing!!!!"< TTofScalerBoard = "< Probably the TRIGLOG SCALER sub-event is not there in this event!"< never 0 except on first event! for( UInt_t uScaler = 0; uScaler GetScalerValue( uCh, uScaler); if( fuFirstMbsTime[iTrigScalIndex] == 0 ) fuFirstScaler[iTrigScalIndex][uScaler][uCh] = fuLastScaler[iTrigScalIndex][uScaler][uCh]; } // for( UInt_t uCh = 0; uCh < triglog::kuNbChan; uCh++) fuLastMbsTime[iTrigScalIndex] = uMbsTime; if( 0 == fuFirstMbsTime[iTrigScalIndex] ) fuFirstMbsTime[iTrigScalIndex] = fuLastMbsTime[iTrigScalIndex]; } // if( 0 < fuNbTriglogScal ) else LOG(ERROR)<<"TTofTriglogScalUnpacker::UpdateStats => No TRIGLOG board active as scaler!!!!!" <<" recheck your VME address matrix "< No TRIGLOG board active as scaler!!!!!" <<" recheck your VME address matrix "<cd(); // <= To prevent histos from being sucked in by the param file of the TRootManager ! Double_t dEvoRange = triglog::kdEvoRange; Double_t dEvoBinNb = triglog::kdEvoRange / triglog::kdEvoBin; if( 0 < fdEvoRangeUser && 0 < fdEvoBinSzUser && fdEvoBinSzUser < fdEvoRangeUser ) { dEvoRange = fdEvoRangeUser; dEvoBinNb = static_cast(fdEvoRangeUser) / static_cast(fdEvoBinSzUser); LOG(INFO)<<"TTofTriglogScalUnpacker::CreateHistos => Set the scaler evolution plot with user range: " << dEvoRange << " s/range " << fdEvoBinSzUser << " s/bin " << dEvoBinNb << " bins "<(dEvoBinNb), 0.0, dEvoRange ); } // for( UInt_t uScaler = 0; uScaler cd( oldir->GetPath() ); // <= To prevent histos from being sucked in by the param file of the TRootManager! } // if( 0 < fuNbTriglogScal ) else LOG(ERROR)<<"TTofTriglogScalUnpacker::CreateHistos => No TRIGLOG board active as scaler!!!!!" <<" recheck your VME address matrix "<At(fuTrigOff + uScalIndex); if( NULL == fScalerBoard ) { LOG(ERROR)<<"TTofTriglogScalUnpacker::FillHistos => Board objects not existing!!!!"< TTofScalerBoard = "< Probably the TRIGLOG SCALER sub-event is not there in this event!"<GetEntries())< never 0 except on first event! fdFirstMbsTime[uScalIndex] = fdCurrMbsTime[uScalIndex]; */ // Fix attempt if( kTRUE == fParUnpack->WithActiveTriglog() ) { TTofTriglogBoard * fTriglogBoard = (TTofTriglogBoard*) fTriglogBoardCollection->At(0); // Always only 1 TRIGLOG board! fdCurrMbsTime[uScalIndex] = fTriglogBoard->GetMbsTimeSec(); if( 0 == fdFirstMbsTime[uScalIndex] ) // MBS time is time in s since LINUX epoch (circa 1970) => never 0 except on first event! fdFirstMbsTime[uScalIndex] = fdCurrMbsTime[uScalIndex]; } if( ( 0 == fdPrevMbsTime[uScalIndex] ) || ( fdPrevMbsTime[uScalIndex] + 0.05 < fdCurrMbsTime[uScalIndex] ) ) { Double_t dTimeDiff = fdCurrMbsTime[uScalIndex] - fdPrevMbsTime[uScalIndex]; if( 0 < fdPrevMbsTime[uScalIndex] && dTimeDiff < 0.3 ) { fhRefClkRate[uScalIndex]->Fill( (Double_t)(fScalerBoard->GetRefClk() - fuLastRefClk[uScalIndex] ) / dTimeDiff ); fhRefClkRateEvo[uScalIndex]->Fill(fdCurrMbsTime[uScalIndex] - fdFirstMbsTime[uScalIndex], fScalerBoard->GetRefClk() - fuLastRefClk[uScalIndex]); } // if( 0 < fdPrevMbsTime ) fdPrevMbsTime[uScalIndex] = fdCurrMbsTime[uScalIndex]; fuLastRefClk[uScalIndex] = fScalerBoard->GetRefClk(); } // if( ( 0 == fdPrevMbsTime ) || ( dMbsTime > fdPrevMbsTime + 0.1 ) ) for( UInt_t uScaler = 0; uScaler SetBinContent( 1 + uCh, fScalerBoard->GetScalerValue( uCh, uScaler) - fuFirstScaler[uScalIndex][uScaler][uCh] ); fhScalersCountsEvo[uScalIndex][uScaler][uCh]->SetBinContent( fdCurrMbsTime[uScalIndex] - fdFirstMbsTime[uScalIndex], fScalerBoard->GetScalerValue( uCh, uScaler) ); } // for( UInt_t uCh = 0; uCh < triglog::kuNbChan; uCh++) } // for( UInt_t uScalIndex = 0; uScalIndex < fuNbTriglogScal; uScalIndex++) } void TTofTriglogScalUnpacker::WriteHistos( TDirectory* inDir) { // Some triglog board can be used as scaler board instead of trigger source for( UInt_t uScalIndex = 0; uScalIndex < fuNbTriglogScal; uScalIndex++) { TDirectory * oldir = gDirectory; TDirectory *cdTriglog = inDir->mkdir( Form( "Unp_%s_%02u", tofscaler::ksTdcHistName[ tofscaler::triglogscal ].Data(), uScalIndex ) ); cdTriglog->cd(); // make the "Unp_triglog" directory the current directory fhRefClkRate[uScalIndex]->Write(); fhRefClkRateEvo[uScalIndex]->Write(); for( UInt_t uScaler = 0; uScaler Write(); for( UInt_t uCh = 0; uCh < triglog::kuNbChan; uCh++) fhScalersCountsEvo[uScalIndex][uScaler][uCh]->Write(); } // for( UInt_t uScaler = 0; uScaler cd( oldir->GetPath() ); } // for( UInt_t uScalIndex = 0; uScalIndex < fuNbTriglogScal; uScalIndex++) } void TTofTriglogScalUnpacker::DeleteHistos() { /* // Some triglog board can be used as scaler board instead of trigger source if( 0 < fuNbTriglogScal ) { } // if( 0 < fuNbTriglogScal ) else LOG(ERROR)<<"TTofTriglogScalUnpacker::DeleteHistos => No TRIGLOG board active as scaler!!!!!" <<" recheck your VME address matrix "<