206 #include "StRoot/StEvent/StEvent.h"
207 #include "StRoot/StEvent/StFgtCollection.h"
208 #include "StRoot/StEvent/StFgtStripCollection.h"
209 #include "StRoot/StEvent/StFgtStrip.h"
210 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
211 #include "StRoot/StFgtDbMaker/StFgtDb.h"
212 #include "StFgtA2CMaker.h"
216 mStatusMask(0xff), mAbsThres(-10000), mRelThres(4.0),mClusterThreshold(1.0),
217 mPedSigFactor4Charge(1.0), mUseLeastRestrictiveSeed(true) ,mReadPedFile(0), mReadStatusFile(0), mDb(0) {
230 LOG_INFO <<
"StFgtA2CMaker::Init we are named " <<
GetName() << endm;
238 LOG_INFO <<
"StFgtA2CMaker::InitRun for " << runumber << endm;
240 LOG_INFO <<
"No fgtDb yet, trying to get a hold" << endm;
244 LOG_FATAL <<
"StFgtDb not provided and error finding StFgtDbMaker" << endm;
248 mDb = fgtDbMkr->getDbTables();
251 LOG_FATAL <<
"StFgtDb not provided and error retrieving pointer from StFgtDbMaker '"
252 << fgtDbMkr->
GetName() << endm;
255 LOG_INFO <<
"Got on hold on fgtDb, all OK" << endm;
275 eventPtr = (
StEvent*) GetInputDS(
"StEvent");
278 LOG_ERROR <<
"Error getting pointer to StEvent from '" << ClassName() <<
"'" << endm;
285 fgtCollectionPtr=eventPtr->fgtCollection();
288 if( !fgtCollectionPtr) {
289 LOG_ERROR <<
"Error getting pointer to StFgtCollection from '" << ClassName() <<
"'" << endm;
294 mMaxTimeBin=fgtCollectionPtr->getNumTimeBins();
295 if(mMaxTimeBin==0)
return 0;
296 for( UInt_t discIdx=0; discIdx<fgtCollectionPtr->getNumDiscs(); ++discIdx ){
299 if( stripCollectionPtr ){
301 StSPtrVecFgtStrip& stripVec = stripCollectionPtr->getStripVec();
302 StSPtrVecFgtStripIterator stripIter;
304 for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
307 Float_t ped = 0, pedErr = 0;
309 Int_t nTbAboveThres = 0;
312 strip->setMaxAdc(-9999);
314 Int_t rdo, arm, apv, chan;
315 strip->getElecCoords( rdo, arm, apv, chan );
316 Int_t elecId = StFgtGeom::encodeElectronicId( rdo, arm, apv, chan );
322 if(mPedFilename.empty()){
323 ped = mDb->getPedestalFromElecId( elecId );
324 pedErr = mDb->getPedestalSigmaFromElecId( elecId );
326 readPedFile(elecId,ped,pedErr);
330 strip->setPedErr(pedErr);
333 if( ped > kFgtMaxAdc || ped < 0 ){
334 strip->setGeoId( -1 );
336 for( Int_t timebin = 0; timebin < mMaxTimeBin && strip->getGeoId() > -1; ++timebin ){
337 Int_t adc = strip->getAdc( timebin );
340 Int_t adcMinusPed = adc - ped;
341 strip->setAdc(adcMinusPed, timebin );
344 if( adcMinusPed > -1000)
347 if( (mRelThres && adcMinusPed > mRelThres*pedErr) || (mAbsThres>-kFgtMaxAdc && adcMinusPed > mAbsThres)) {
358 Double_t gain = mDb->getGainFromElecId( elecId );
361 strip->setCharge( sumC/gain );
369 strip->setChargeUncert(gain ? mPedSigFactor4Charge*sqrt(7)*pedErr/gain : 10000);
372 if( !nTbAboveThres && (mRelThres || mAbsThres>-kFgtMaxAdc) ){
375 strip->setClusterSeedType(kFgtSeedTypeNo);
377 }
else if( mRelThres || mAbsThres>-kFgtMaxAdc ){
384 strip->invalidateCharge();
387 if( mStatusMask != 0x0 ){
389 if(mStatusFilename.empty()){
390 status=mDb->getStatusFromElecId( elecId );
392 readStatusFile(elecId,status);
394 if( status & mStatusMask )
395 strip->setClusterSeedType(kFgtDeadStrip);
426 stripCollectionPtr->removeFlagged();
440 Float_t peakAdc = -9999;
441 Int_t leadEdgeBin = -9999;
443 Int_t numHighBins = 0;
444 Int_t numAlmostHighBins = 0;
445 Int_t numTailHighBins = 0;
446 Int_t numHighBinsAfterLeadingEdge = 0;
447 Int_t numPlateau = 0;
448 Int_t numMaxPlateau = 0;
451 if(pStrip->getGeoId()<0)
return kFgtSeedTypeNo;
453 for( Int_t timebin = 0; timebin < mMaxTimeBin; ++timebin ) {
454 Float_t adc=pStrip->getAdc(timebin);
457 if(prvAdc>0 && fabs(prvAdc-adc)<ped && adc>3*ped) {
461 if(numPlateau>numMaxPlateau) {
462 numMaxPlateau=numPlateau;
476 if( leadEdgeBin<0 && adc>5*ped )
479 if(2<=timebin && timebin <=4 && peakAdc<adc)
481 if(2<=timebin && timebin <=4 && adc>5*ped)
483 if(2<=timebin && timebin <=4 && adc>3*ped)
485 if(5<=timebin && timebin <=6)
490 if(!mAcceptLongPulses)
492 if(numMaxPlateau>=3) {
494 return kFgtSeedTypeNo;
501 if(pStrip->getAdc(0) <3*ped && numHighBins==3 && peakAdc > pStrip->getAdc(6) && numAlmostHighBins>=3 && numHighBinsAfterLeadingEdge>=2) {
502 return kFgtSeedType1;
505 if(pStrip->getAdc(0) <3*ped && numHighBins==2 && peakAdc > pStrip->getAdc(6)&& numHighBinsAfterLeadingEdge>=2)
506 return kFgtSeedType2;
512 if(pStrip->getCharge() < 1.732*mClusterThreshold*5*ped)
return kFgtSeedTypeNo;
514 float maxadc=0, adc[kFgtNumTimeBins];
516 for( Int_t t=0; t < mMaxTimeBin; t++ ) {
517 adc[t]=pStrip->getAdc(t);
518 if(adc[t]>maxadc) {maxadc=adc[t]; maxt=t;}
520 if(maxt==0)
return kFgtSeedTypeNo;
521 if(maxt>=9)
return kFgtSeedTypeNo;
523 for( Int_t t = 0; t < mMaxTimeBin-2; t++ ) {
524 float thr=mClusterThreshold*5*ped;
525 if(adc[t]>thr && adc[t+1]>thr && adc[t+2]>thr) {flag=1;
break;}
533 if(flag==0)
return kFgtSeedTypeNo;
534 if(adc[0]>=maxadc/3.0)
return kFgtSeedTypeNo;
536 if(adc[mMaxTimeBin-1]<maxadc)
return kFgtSeedType3;
537 return kFgtSeedType4;
549 void StFgtA2CMaker::readPedFile(Int_t elecid, Float_t &ped, Float_t &pedrms){
551 LOG_INFO <<
"Reading pedestal from a text file ="<<mPedFilename.data()<<endm;
555 memset(mPed,0,
sizeof(mPed));
556 memset(mPedRMS,0,
sizeof(mPedRMS));
557 file.open(mPedFilename.data());
560 file>>eid>>tbin>>p>>s;
561 LOG_DEBUG<<
"Reading Ped: "<<eid<<
" "<<tbin<<
" "<<p<<
" "<<s<<endm;
566 LOG_INFO<<
"Reading pedestal from a text file failed"<<endm;
572 pedrms=mPedRMS[elecid];
575 void StFgtA2CMaker::readStatusFile(Int_t elecid, UInt_t &status){
576 if(mReadStatusFile==0){
577 LOG_INFO <<
"Reading status from a text file ="<<mStatusFilename.data()<<endm;
578 unsigned int eid,stat;
581 memset(mStatus,1,
sizeof(mStatus));
582 file.open(mStatusFilename.data());
586 statread.Remove(0,2);
587 stat = statread.Atoi();
588 LOG_DEBUG<<
"Reading Status: "<<eid<<
" "<<stat<<endm;
592 LOG_INFO<<
"Reading status from a text file failed"<<endm;
597 status=mStatus[elecid];
Int_t Init()
Does nothing else than printing "we are here".
Int_t InitRun(Int_t runumber)
Get pointer to fgtDb.
virtual const char * GetName() const
special overload
~StFgtA2CMaker()
destructor - really does nothing
StFgtA2CMaker(const Char_t *name="fgtA2CMaker")
Class constructors - does nothing else than setting name.
Short_t checkValidPulse(StFgtStrip *pStrip, Float_t ped)
Returns true for a valid pulse.