53 #include "StFgtStatusMaker.h"
54 #include "StRoot/StFgtDbMaker/StFgtDb.h"
55 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
56 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
57 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
58 #include "StRoot/StFgtUtil/StFgtConsts.h"
59 #include "StRoot/StFgtPool/StFgtPedMaker/StFgtPedMaker.h"
62 StFgtStatusMaker::StFgtStatusMaker(
const Char_t* name,
const Char_t* pedMakerName ) :
63 StMaker( name ), mPedMkrName( pedMakerName ), mPedMkr(0), mTimeBin(2),
64 mMinPed( 100 ), mMaxPed( 1200 ), mMinRMS( 10 ), mMaxRMS( 80 ), mMinFrac( 0.6 ), mMaxFrac( 0.95 ), mMaxDead( 64 ), mHasFinished( 0 ) {
66 mStatus =
new status_t [ kFgtNumElecIds ];
67 mApvData.resize( kFgtNumRdos * kFgtNumArms * kFgtApvsPerArm );
71 StFgtStatusMaker::~StFgtStatusMaker(){
77 Int_t StFgtStatusMaker::Init(){
81 if( !mFilename.empty() ){
82 std::ofstream fout( mFilename.data() );
84 LOG_FATAL <<
"Error opening file '" << mFilename <<
"'" << endm;
90 mPedMkr =
static_cast< StFgtPedMaker*
>( GetMaker( mPedMkrName.data() ) );
92 LOG_FATAL <<
"Cannot find StFgtPedMaker" << endm;
98 if( !mPedMkr->mTimeBinMask & (1<<mTimeBin) ){
99 LOG_WARN <<
"StFgtPedMaker is not set to compute the time bin needed for StFgtStatusMaker" << endm;
100 mPedMkr->mTimeBinMask |= (1<<mTimeBin);
101 LOG_WARN <<
"StFgtPedMaker::mTimeBinMask set to 0x" << std::hex << mPedMkr->mTimeBinMask << std::dec << endm;
106 UChar_t defaultValue = (1<<INVALID_ID);
107 for( UChar_t *p = mStatus; p != &mStatus[ kFgtNumElecIds ]; ++p )
110 mApvData.assign( kFgtNumRdos * kFgtNumArms * kFgtApvsPerArm, apvData_t() );
122 if( !mPedMkr->mHasFinished )
125 StFgtPedMaker::pedDataVec_t& pedVec = mPedMkr->mDataVec;
126 StFgtPedMaker::pedDataVec_t::iterator pedVecIter;
130 cout <<
"StFgtStatusMaker::Finish()" << endl;
132 if( !mPedMkr->mDbMkrName.empty() ){
133 if( !mPedMkr->mFgtDbMkr ){
134 LOG_FATAL <<
"Pointer to Fgt DB Maker is null" << endm;
138 fgtTables = mPedMkr->mFgtDbMkr->getDbTables();
141 LOG_FATAL <<
"Pointer to Fgt DB Tables is null" << endm;
150 for( pedVecIter = pedVec.begin(); pedVecIter != pedVec.end(); ++pedVecIter, ++pedIdx ){
152 Int_t timebin = pedIdx % kFgtNumTimeBins;
154 if( timebin == mTimeBin ){
155 Int_t elecId = pedIdx / kFgtNumTimeBins;
156 UChar_t& status = mStatus[ elecId ];
161 if( pedVecIter->ped < mMinPed || pedVecIter->ped > mMaxPed )
162 status |= (1<<PED_OUT_OF_RANGE);
164 if( pedVecIter->RMS < mMinRMS || pedVecIter->RMS > mMaxRMS )
165 status |= (1<<RMS_OUT_OF_RANGE);
167 if( pedVecIter->fracClose < mMinFrac || pedVecIter->fracClose > mMaxFrac )
168 status |= (1<<FRAC_OUT_OF_RANGE);
173 data.stripStatusVec.push_back( &mStatus[ elecId ] );
179 UChar_t deadStatus = (1<<APV_DEAD);
180 apvDataVec_t::iterator apvDataIter;
181 std::vector< status_t* >::iterator statusPtrIter;
182 for( apvDataIter = mApvData.begin(); apvDataIter != mApvData.end(); ++apvDataIter )
183 if( apvDataIter->numDead > mMaxDead )
184 for( statusPtrIter = apvDataIter->stripStatusVec.begin(); statusPtrIter != apvDataIter->stripStatusVec.end(); ++statusPtrIter )
185 *(*statusPtrIter) |= deadStatus;
188 if( !ierr && !mFilename.empty() )
196 Int_t StFgtStatusMaker::saveToFile(){
199 if( !mFilename.empty() ){
200 std::ofstream fout( mFilename.data(), std::ios_base::out & std::ios_base::trunc );
203 LOG_ERROR <<
"Error opening file '" << mFilename <<
"'" << endm;
209 UChar_t badId = (1<<INVALID_ID);
212 for( UChar_t *statusPtr = mStatus; statusPtr != &mStatus[ kFgtNumElecIds ]; ++statusPtr, ++elecId )
213 if( !( *statusPtr & badId ) )
214 fout << std::dec << elecId <<
" 0x" << std::hex << (UShort_t)(*statusPtr) << endl;