67 #include "StFgtPedMaker.h"
68 #include "StRoot/StEvent/StFgtCollection.h"
69 #include "StRoot/StEvent/StFgtStrip.h"
70 #include "StRoot/StEvent/StEvent.h"
71 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
72 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
73 #include "StRoot/StFgtUtil/StFgtConsts.h"
76 StFgtPedMaker::StFgtPedMaker(
const Char_t* name ) :
StMaker( name ), mHasFinished(0) {
78 mDataVec.resize( kFgtNumTimeBins * kFgtNumElecIds );
82 Int_t StFgtPedMaker::Init(){
85 if( !mFilename.empty() ){
87 std::ofstream fout( mFilename.data() );
89 LOG_ERROR <<
"Error opening file '" << mFilename <<
"'" << endl;
95 if( !ierr && !mDbMkrName.empty() ){
97 mFgtDbMkr =
static_cast< StFgtDbMaker*
>( GetMaker( mDbMkrName.data() ) );
99 if( !ierr && !mFgtDbMkr ){
100 LOG_FATAL <<
"Error finding FgtDbMkr" << endm;
104 if( !mFgtDbMkr->InheritsFrom(
"StFgtDbMaker") ){
105 LOG_FATAL <<
"StFgtDbMkr does not inherit from StFgtDbMaker" << endm;
106 LOG_FATAL <<
"Name is '" << mFgtDbMkr->
GetName() <<
"', class is '" << mFgtDbMkr->ClassName() << endm;
120 eventPtr = (
StEvent*)GetInputDS(
"StEvent");
123 LOG_ERROR <<
"Error getting pointer to StEvent from '" << ClassName() <<
"'" << endm;
130 fgtCollectionPtr=eventPtr->fgtCollection();
133 if( !fgtCollectionPtr) {
134 LOG_ERROR <<
"Error getting pointer to StFgtCollection from '" << ClassName() <<
"'" << endm;
139 for( UInt_t discIdx=0; discIdx<fgtCollectionPtr->getNumDiscs(); ++discIdx ){
141 if( stripCollectionPtr ){
142 StSPtrVecFgtStrip& stripVec = stripCollectionPtr->getStripVec();
143 StSPtrVecFgtStripIterator stripIter;
145 for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
146 for( Int_t timeBin = 0; timeBin < kFgtNumTimeBins; ++timeBin ){
147 Bool_t pass = (( 1<<timeBin & mTimeBinMask ) && timeBin > 0 && timeBin < kFgtNumTimeBins);
150 Int_t rdo, arm, apv, channel;
151 (*stripIter)->getElecCoords( rdo, arm, apv, channel );
152 Int_t elecId = StFgtGeom::getElectIdFromElecCoord( rdo, arm, apv, channel );
153 Short_t adc = (*stripIter)->getAdc( timeBin );
156 Int_t code = kFgtNumTimeBins * elecId + timeBin;
161 data.sumsq += adc*adc;
179 cout <<
"StFgtPedMaker::Finish()" << endl;
182 pedDataVec_t::iterator dataVecIter;
183 for( dataVecIter = mDataVec.begin(); dataVecIter != mDataVec.end(); ++dataVecIter ){
185 Int_t n = dataVecIter->n;
189 dataVecIter->sum /= n;
192 dataVecIter->sumsq /= n;
193 dataVecIter->sumsq -= dataVecIter->sum * dataVecIter->sum;
194 dataVecIter->sumsq = sqrt( dataVecIter->sumsq );
199 if( dataVecIter->ped != dataVecIter->ped ){
200 dataVecIter->ped = 0;
201 dataVecIter->RMS = 10000;
202 }
else if ( dataVecIter->RMS != dataVecIter->RMS ){
203 dataVecIter->RMS = 10000;
215 Int_t StFgtPedMaker::saveToFile(){
218 if( !mFilename.empty() ){
219 std::ofstream fout( mFilename.data(), std::ios_base::out & std::ios_base::trunc );
222 if( !mDbMkrName.empty() ){
224 LOG_FATAL <<
"Pointer to Fgt DB Maker is null" << endm;
228 fgtTables = mFgtDbMkr->getDbTables();
231 LOG_FATAL <<
"Pointer to Fgt DB Tables is null" << endm;
238 LOG_ERROR <<
"Error opening file '" << mFilename <<
"'" << endm;
243 pedDataVec_t::iterator dataVecIter;
245 for( dataVecIter = mDataVec.begin(); dataVecIter != mDataVec.end() && !ierr; ++dataVecIter, ++idx ){
246 Int_t timebin = idx % kFgtNumTimeBins;
247 Int_t elecId = idx / kFgtNumTimeBins;
249 if( dataVecIter->n && ( dataVecIter->ped || dataVecIter->RMS ) )
250 fout << elecId <<
' ' << timebin <<
' ' << dataVecIter->ped <<
' ' << dataVecIter->RMS << endl;
virtual const char * GetName() const
special overload