#include "hades.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hrichringfindIPU.h"
#include "hrichanalysisIPU.h"
#include "hrichIPUparpattern.h"
#include "hrichIPUparthresholds.h"
#include "hrichIPUparlocmax.h"
#include "hrichhitIPU.h"
#include "htriggersetup.h"
#include "hmessagemgr.h"
ClassImp(HRichRingFindIPU)
const Char_t* HRichRingFindIPU::checkParamContext(void)
{
if (fRichIPUParThr)
{
return fRichIPUParThr->getParamContext();
}
else
{
return NULL;
}
}
Bool_t HRichRingFindIPU::initParContainer(HSpectrometer *spec, HRuntimeDb *rtdb)
{
fRichIPUParPat=(HRichIPUParPattern *)rtdb->getContainer("RichIPUParPattern");
if (fRichIPUParPat)
{
INFO_msg(10,HMessageMgr::DET_TRIGGER,"RichIPU Parameters Pattern initialized");
}
else
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"RichIPU Parameters Pattern Initialization failed!");
return kFALSE;
}
fRichIPUParThr=(HRichIPUParThresholds *)rtdb->getContainer("RichIPUParThresholds");
if (fRichIPUParThr)
{
INFO_msg(10,HMessageMgr::DET_TRIGGER,"RichIPU Parameters Thresholds initialized");
}
else
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"RichIPU Parameters Thresholds Initialization failed!");
return kFALSE;
}
fRichIPUParLmax=(HRichIPUParLocMax *)rtdb->getContainer("RichIPUParLocMax");
if (fRichIPUParLmax)
{
INFO_msg(10,HMessageMgr::DET_TRIGGER,"RichIPU Parameters LocMax initialized");
}
else
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"RichIPU Parameters LocMax Initialization failed!");
return kFALSE;
}
return kTRUE;
}
HRichRingFindIPU::HRichRingFindIPU(void)
{
iRingNr = 0;
pRings = new TObjArray(50);
pRings->SetOwner(kTRUE);
}
Bool_t HRichRingFindIPU::init(HRichAnalysisIPU* showMe)
{
SEPERATOR_msg("-",60);
INFO_msg(10,HMessageMgr::DET_TRIGGER,"INIT of HRichRingFindIPU()");
HSpectrometer *spec = gHades->getSetup();
HRuntimeDb *rtdb = gHades->getRuntimeDb();
HRichDetector * pRichDet = (HRichDetector*)gHades->getSetup()->getDetector("Rich");
if (pRichDet)
{
if(!initParContainer(spec,rtdb))
{
return kFALSE;
}
}
if (pRings)pRings->Clear();
showMe->setRings(&pRings);
SEPERATOR_msg("-",60);
flag =0;
version =0;
return kTRUE;
}
HRichRingFindIPU::~HRichRingFindIPU()
{
if (pRings)
{
delete pRings;
pRings = NULL;
}
}
HRichRingFindIPU::HRichRingFindIPU(const HRichRingFindIPU& source)
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"HRichRingFindIPU object can not be initialized with values of another object!");
ERROR_msg(HMessageMgr::DET_TRIGGER,"Default constructor will be called.");
HRichRingFindIPU();
}
HRichRingFindIPU& HRichRingFindIPU::operator=(const HRichRingFindIPU& source)
{
if (this != &source)
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"HRichRingFindIPU object can not be assigned!");
ERROR_msg(HMessageMgr::DET_TRIGGER,"Default constructor will be called.");
return *(new HRichRingFindIPU());
}
return *this;
}
void HRichRingFindIPU::makeLabelPattern(void)
{
Int_t nn=0;
for (Int_t xx=0; xx < fRichIPUParPat->getNGroups(); xx++)
{
if (fRichIPUParPat->getPattern(xx,0,1)==0)
{
for (Int_t yy=1; yy <= fRichIPUParPat->getPattern(xx,0,0); yy++)
{
Int_t flag2 =0;
for (Int_t zz=0; zz < fRichIPUParPat->getNPadDimensions(); zz++)
{
if(flag2==0)
{
nn++;
flag2=1;
}
if ( (nn>=0) && (nn<65) && (zz>=0) && (zz<2) )
{
setLabelPattern(nn-1,zz,fRichIPUParPat->getPattern(xx,yy,zz));
}
else
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"ARRAY OUT OF SIZE (you never should read this!!)");
}
}
}
}
}
label_size=0;
for (Int_t ii=0; ii<nn; ii++)
{
Int_t flag4=0;
for (Int_t k=0; k<fRichIPUParPat->getNPadDimensions(); k++)
{
Int_t flag3=0;
for (Int_t j=1; j<=ii; j++ )
{
if ( (( (getLabelPattern(ii,0)) == (getLabelPattern(ii-j,0))) &&
( (getLabelPattern(ii,1)) == (getLabelPattern(ii-j,1))) ) )
{
flag3=1;
}
}
if (flag3==0)
{
if(flag4==0)
{
label_size++;
flag4=1;
}
setLabelPattern(label_size-1,k,getLabelPattern(ii,k));
}
}
}
}
Int_t HRichRingFindIPU::Execute(void)
{
if (flag ==0)
{
makeLabelPattern();
flag=1;
}
pRings->Clear();
iRingNr = 0;
for (lr=0; lr<96;lr++)
{
for (lc=0; lc<96;lc++)
{
label[lr][lc]=0;
}
}
for(Int_t r=0; r<96; r++)
{
for(Int_t c=0; c<96; c++)
{
if(pads[Sector][r][c])
{
for(Int_t lnr=0; lnr < label_size; lnr++)
{
lr = r + getLabelPattern(lnr,0);
lc = c + getLabelPattern(lnr,1);
if (lr>=0&&lr<=95&&lc>=0&&lc<=95 )
{
label[lr][lc]++;
}
}
}
}
}
RingSearch();
MaxSearch();
return (iRingNr);
}
void HRichRingFindIPU::ZeroArray()
{
for(Int_t i=0; i<6; i++)
{
for(Int_t j=0; j<96; j++)
{
for (Int_t k=0; k<96; k++)
{
pads[i][j][k] = 0;
}
}
}
}
void HRichRingFindIPU::RingSearch(void)
{
#warning "The ringfinder version is hardcoded here!"
version =2;
Int_t iNumberOfGroups = fRichIPUParPat->getNGroups();
Int_t iNumberOfRegions = 2;
Int_t iGroupsInRegion[iNumberOfRegions];
Int_t px, py;
Int_t iPadsInGroup;
Int_t iTotPads;
Int_t iNumberOfValidRegions;
Int_t patternHit[iNumberOfGroups];
for(Int_t j=0; j<96; j++)
{
for(Int_t k=0; k<96; k++)
{
centers[j][k] = 0;
ringsum[j][k] = 0;
vetosum[j][k] = 0;
nPads[j][k] = 0;
}
}
for(lr=0; lr<96; lr++)
{
for(lc=0; lc<96; lc++)
{
if(label[lr][lc] >0)
{
iNumberOfValidRegions = 0;
for (Int_t j=0; j< iNumberOfRegions; j++)
{
iGroupsInRegion[j]=0;
}
iTotPads = 0;
for (Int_t i=0; i< iNumberOfGroups; i++){
patternHit[i] = 0;
iPadsInGroup = 0;
for(Int_t j=1; j<= fRichIPUParPat->getPattern(i,0,0) ; j++)
{
px = lr + fRichIPUParPat->getPattern(i,j,0);
py = lc - fRichIPUParPat->getPattern(i,j,1);
if(px>=0 && px <=95 && py>=0 && py<=95)
{
if (pads[Sector][px][py])
{
iPadsInGroup++;
if ( fRichIPUParPat->getPattern(i,0,1) == 0 )
{
iTotPads++;
}
}
}
}
if ( iPadsInGroup > 0 )
{
iGroupsInRegion[fRichIPUParPat->getPattern(i,0,1)]++;
patternHit[i] = 1;
}
}
if (version==1)
{
for (Int_t j=0; j< iNumberOfRegions; j++)
{
if (( (fRichIPUParThr->getThresholds(j,Sector)) >= 0
&& iGroupsInRegion[j] > (fRichIPUParThr->getThresholds(j,Sector)) ) ||
( (fRichIPUParThr->getThresholds(j,Sector)) < 0
&& iGroupsInRegion[j] < -(fRichIPUParThr->getThresholds(j,Sector)) ) )
{
iNumberOfValidRegions++;
}
}
ringsum[lr][lc] = iGroupsInRegion[0];
vetosum[lr][lc] = iGroupsInRegion[1];
if ( iNumberOfValidRegions == iNumberOfRegions )
{
centers[lr][lc] = 1;
nPads[lr][lc] = iTotPads/2;
}
}
else
{
if (version==2)
{
for (Int_t j=0; j< iNumberOfRegions; j++)
{
if ( ( (fRichIPUParThr->getThresholds(j,Sector)) >= 0
&& iGroupsInRegion[j] > (fRichIPUParThr->getThresholds(j,Sector)) ) ||
( (fRichIPUParThr->getThresholds(j,Sector)) < 0
&& iGroupsInRegion[j] < -(fRichIPUParThr->getThresholds(j,Sector)) ) )
{
iNumberOfValidRegions++;
}
}
if ( iNumberOfValidRegions == iNumberOfRegions ) {
centers[lr][lc] = 1;
nPads[lr][lc] = iTotPads/2;
ringsum[lr][lc] = iGroupsInRegion[0];
vetosum[lr][lc] = iGroupsInRegion[1];
}
}
else
{
if (version==3)
{
iNumberOfValidRegions=1;
if (iGroupsInRegion[0]-iGroupsInRegion[1] > fRichIPUParThr->getThresholds(0,Sector))
{
iNumberOfValidRegions++;
}
if ( iNumberOfValidRegions == iNumberOfRegions )
{
centers[lr][lc] = 1;
nPads[lr][lc] = iTotPads/2;
ringsum[lr][lc] = iGroupsInRegion[0];
vetosum[lr][lc] = iGroupsInRegion[1];
}
}
}
}
}
}
}
}
void HRichRingFindIPU::MaxSearch(void)
{
for(lr=0; lr<96; lr++)
{
for(lc=0; lc<96; lc++)
{
if(centers[lr][lc] >0)
{
Int_t fulfill=0;
if (fRichIPUParLmax->getLocMaxFlag()==1)
{
if ( (fRichIPUParLmax->getLocMax()==4)||(fRichIPUParLmax->getLocMax()==8) )
{
if( ((version==1)&&
( ringsum[lr][lc] >= ringsum[lr+1][lc] &&
ringsum[lr][lc] >= ringsum[lr][lc+1] &&
ringsum[lr][lc] > ringsum[lr-1][lc] &&
ringsum[lr][lc] > ringsum[lr][lc-1] ) ) ||
((version==2)&&
( ringsum[lr][lc] > ringsum[lr+1][lc] &&
ringsum[lr][lc] >= ringsum[lr][lc+1] &&
ringsum[lr][lc] >= ringsum[lr-1][lc] &&
ringsum[lr][lc] > ringsum[lr][lc-1] ) ) )
{
if (fRichIPUParLmax->getLocMax()==8)
{
if( ringsum[lr][lc] >= ringsum[lr+1][lc+1] &&
ringsum[lr][lc] >= ringsum[lr-1][lc+1] &&
ringsum[lr][lc] > ringsum[lr-1][lc-1] &&
ringsum[lr][lc] > ringsum[lr+1][lc-1] )
{
fulfill=1;
}
}
else
{
fulfill=1;
}
}
}
else
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"wrong parameter value!!!");
}
}
else
{
fulfill=1;
}
if ( fulfill==1 )
{
fillHit(lr,lc,ringsum[lr][lc],vetosum[lr][lc],nPads[lr][lc]);
}
}
}
}
}
void HRichRingFindIPU::fillHit(Int_t row, Int_t column, Int_t quality, Int_t vetoQuality, Int_t nPads)
{
HRichHitIPUCont *hitCont = new HRichHitIPUCont();
if(hitCont == NULL)
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"No entry at the position!");
return;
}
HRichHitIPU *hit = hitCont->getData();
if(hit == NULL)
{
ERROR_msg(HMessageMgr::DET_TRIGGER,"No entry at the position!");
return;
}
if ( iRingNr < 4999 )
{
iRingNr++;
}
else
{
INFO_msg(10,HMessageMgr::DET_TRIGGER,"iRingNr reached MAXIMUM!!!");
}
hit->setX(column);
hit->setY(row);
hit->setQuality(quality);
hit->setVetoQuality(vetoQuality);
hit->setNPads(nPads);
pRings->Add(hitCont);
}
Last change: Sat May 22 13:09:58 2010
Last generated: 2010-05-22 13:09
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.