// File: hclusterselector.cc // // Author: Laura Fabbietti // Last update by Laura Fabbietti: 02/10/10 13:14:01 // // File: //hclusterselector.cc // // //***************************************************************************** //***************************************************************************** // #include "hclusterselector.h" #include "hruntimedb.h" #include "hevent.h" #include "hspectrometer.h" #include "hdetector.h" #include "hrichdetector.h" #include "hcategory.h" #include "hiterator.h" #include "hmatrixcatiter.h" #include "hlinearcatiter.h" #include "hlocation.h" #include "hrichcal.h" #include "hphotoncluster.h" #include "hdebug.h" #include "hades.h" #include "richdef.h" #include "hrichgeometrypar.h" #include "hrichlocalmaxheader.h" ClassImp(HClusterSelector) HClusterSelector::HClusterSelector(const Text_t *name,const Text_t *title, Int_t hitMin, Int_t secShadow, Float_t minTheta1, Float_t maxTheta1, Float_t minTheta2, Float_t maxTheta2, Int_t secEdge1, Int_t secEdge2,Int_t minHitsecEdge1, Int_t minHitsecEdge2) : HReconstructor(name,title) { edgesector1 = secEdge1; edgesector2 = secEdge2; minHitedgesector1 =minHitsecEdge1; minHitedgesector2 = minHitsecEdge2; minHit = hitMin; fIter = NULL; fIter1 = NULL; thetaMin1 = minTheta1; thetaMax1 = maxTheta1; thetaMin2 = minTheta2; thetaMax2 = maxTheta2; eventNr = 1; shadowSector = secShadow; padCounter = 0; } HClusterSelector::~HClusterSelector(void) { if (fIter) delete fIter; if (fIter1) delete fIter1; if(pLeftBorder) delete [] pLeftBorder; if(pRightBorder) delete [] pRightBorder; } Bool_t HClusterSelector::init() { printf("initialization of rich localmaxcal\n"); HRichDetector *pRichDet = (HRichDetector*) gHades -> getSetup() -> getDetector("Rich"); fLocalCatHr=gHades->getCurrentEvent()->getCategory(catRichLocalMaxHeader); if (!fLocalCatHr) { fLocalCatHr=pRichDet->buildCategory(catRichLocalMaxHeader); if (!fLocalCatHr) return kFALSE; else gHades->getCurrentEvent() ->addCategory(catRichLocalMaxHeader,fLocalCatHr, "Rich"); } fCalCat = gHades -> getCurrentEvent() -> getCategory(catRichCal); if (!fCalCat) { fCalCat = pRichDet -> buildCategory(catRichCal); if (!fCalCat) return kFALSE; else gHades -> getCurrentEvent() -> addCategory(catRichCal, fCalCat,"Rich"); } fIter = (HMatrixCatIter*) getCalCat() -> MakeIterator(); fPhotClusCat= gHades -> getCurrentEvent() -> getCategory(catRichPhotClus); if (!fPhotClusCat) { fPhotClusCat= pRichDet -> buildCategory(catRichPhotClus); if (!fPhotClusCat) return kFALSE; else gHades -> getCurrentEvent() -> addCategory(catRichPhotClus, fPhotClusCat ,"Rich"); } fIter1 = (HMatrixCatIter*) getPhotClusCat() -> MakeIterator(); HRuntimeDb* rtdb = gHades -> getRuntimeDb(); pGeomPar = (HRichGeometryPar*) rtdb -> getContainer("RichGeometryParameters"); if (pGeomPar == NULL) { pGeomPar = new HRichGeometryPar; rtdb -> addContainer(pGeomPar); } setGeometryPar(pGeomPar); if (pGeomPar == NULL) return kFALSE; tCharge = new TNtuple("tCharge","tCharge","padNr:q0:q1:q2:q3:q4:q5:q6:q7:q8:qSum:iSec:iClass:theta:phi"); tCharge1 = new TNtuple("tCharge1","tCharge1","padNr:q0:q1:q2:q3:q4:q5:q6:q7:q8:qSum:iSec:iClass:xDim:yDim"); tCharge -> SetAutoSave(); tCharge1 -> SetAutoSave(); return kTRUE; } Bool_t HClusterSelector::reinit(){ // maxCols = pGeomPar->getColumns(); maxCols = 92; maxRows = 90; // cout<getPadsPar()->getPad(col+padOffset)->getPadActive() && colgetPadsPar()->getPad(col+padOffset)->getPadActive() && col Write(); tCharge1 -> Write(); return kTRUE; } Int_t HClusterSelector::execute() { // cout<<" executing hclusterselector "< Reset(); count1 = count2 = 0; fTheta1 = fTheta2 = 0; padCounter = 0; //fill the matrixes with data from cal container while ((pCal = (HRichCal *) fIter -> Next())) { loc = fIter -> getLocation(); fillmatrix(loc); padCounter++; } //if the counter i == 0 there is no event copied to the matrix //cal must be empty!!! if ( padCounter== 0) { cout<<"fillmatrix false !!!"<0){ // cout<<" ******************* new pad in sector ************"< getNewSlot(fLoc)); photClus = new(photClus) HPhotonCluster; padTotNr = 0; chargeTot = 0.; chainPads(secNum,row,col,photClus); photClus->setiPadNr(padTotNr); photClus->setSector(secNum); photClus->setfTotalCharge(chargeTot); calcClusProp(photClus); } } } } void HClusterSelector::chainPads(Int_t iSec,Int_t iRow,Int_t iCol,HPhotonCluster* pClus){ //for each fired pad it is checked if the 4 (up-down-sides) neighbours have fired, as long as no fired neighbours is left. IN this way the cluster is built, while collecting the pads belongning to the clusters the pClus is updated. HLocation loc; for(Int_t m =-1;m<2;m++){ for(Int_t n =-1;n<2;n++){ if(m*n==0){ //cout<<"charge "<0&&mPadLock[iSec][iRow+m][iCol+n]==1){ // cout<<"charge "<getObject(loc))<getObject(loc))) pClus->addToTheList((HRichCal*)(((HMatrixCategory*)getCalCat())->getObject(loc))); chainPads(iSec,iRow+m,iCol+n,pClus); } } } } /// cout<<" out of the loop "<sortListByCharge(); pPhotClus->calculatemaxmin(); pPhotClus->setfPhiMaxThetaMax(pGeomPar); Int_t nPad = pPhotClus->getiPadNr(); if (nPad<3){ pPhotClus->setiClass(1); } else { if(nPad==3){ if (isMaximumInCentre(pPhotClus)) pPhotClus->setiClass(1); else pPhotClus->setiClass(2); } else { if(nPad==4 && isMaximumInCentre(pPhotClus)&& thereIsOnlyOneMax(pPhotClus) && pPhotClus->getiXDimension()==2 &&pPhotClus->getiYDimension()==3) pPhotClus->setiClass(1); else pPhotClus->setiClass(3); } } //The charge distribution of the pads around the local maxima is checked // only those pads belonging to the cluster are considered Int_t iRow = ((HRichCal*)pPhotClus->getPadInList(0))->getRow(); Int_t iCol = ((HRichCal*)pPhotClus->getPadInList(0))->getCol(); Int_t iSector = pPhotClus->getSector(); Int_t k = 0; for (Int_t jRow = iRow-1; jRow < iRow+2; jRow++) { for (Int_t jCol = iCol-1; jCol < iCol+2; jCol++) { fCharge[k] = 0.; if(pPhotClus->isInPadList(jCol,jRow)) fCharge[k] = mCharge[iSector][jRow][jCol]; k++; } } tCharge -> Fill(nPad,fCharge[0],fCharge[1],fCharge[2], fCharge[3],fCharge[4],fCharge[5],fCharge[6], fCharge[7],fCharge[8],pPhotClus->getfTotalCharge() ,iSector,pPhotClus->getiClass(), pPhotClus->getfThetaMax(),pPhotClus->getfPhiMax()); tCharge1 -> Fill(nPad,fCharge[0],fCharge[1],fCharge[2], fCharge[3],fCharge[4],fCharge[5],fCharge[6], fCharge[7],fCharge[8],pPhotClus->getfTotalCharge() ,iSector,pPhotClus->getiClass(), pPhotClus->getiXDimension(),pPhotClus->getiYDimension()); // cout<<" cluster class "<getiClass()<getiPadNr() //<getSector()<getPadInList(0))->getCharge(); if(chargeMax>(pPhotC->getfTotalCharge())*0.5) return kTRUE; else return kFALSE; } Bool_t HClusterSelector::isMaximumInCentre(HPhotonCluster *pPhotC){ //cout<<" in isMaximumInCentre "<getPadInList(0); Int_t rowOfmax = dummy->getRow(); Int_t colOfmax = dummy->getCol(); Int_t secOfmax = dummy->getSector(); Int_t countNeig = 0; for(Int_t m =-1;m<2;m++){ for(Int_t n =-1;n<2;n++){ if(m*n==0){ if(mCharge[secOfmax][rowOfmax+m][colOfmax+n]>0) countNeig++; } } } //cout<<" countNeig "<=3) return kTRUE; else return kFALSE; } Bool_t HClusterSelector::fillmatrix(HLocation& fLoc) { //writes hit and charge from cal container for active pads into matrix //writes theta and phi from pad container for active pads into matrix HRichCal *cal = NULL; cal = (HRichCal*) fCalCat -> getObject(fLoc); iCol = cal -> getCol(); iRow = cal -> getRow(); iSector = cal -> getSector(); HRichPad *pad = ((HRichGeometryPar*) pGeomPar) -> getPadsPar()->getPad(iCol,iRow); //cout<<" in fill matrix pad : "< getCharge(); meanCharge[iSector]= meanCharge[iSector]+mCharge[iSector][iRow][iCol]; //mTheta,mPhi are used to calculate the polar and azymutal angle of the photon clusters. mTheta[iSector][iRow][iCol] = pad -> getTheta(); mPhi[iSector][iRow][iCol] = pad -> getPhi(iSector); //cout<<" charge "< getTheta())>thetaMin1&& (pad -> getTheta()) getTheta())>thetaMin2&&(pad -> getTheta())minHit) || (iSector == shadowSector)) {//$$ i++; } } //cout<<" index "<=3 && sumHit[edgesector1]>minHitedgesector1&& sumHit[edgesector2]>minHitedgesector2 ) { hitControl = kTRUE; // cout<<" update headers "<getObject(loc); // cout<<" localHr "<getSlot(loc); if(localHr!=NULL){ localHr = new(localHr) HRichLocalMaxHeader; localHr->setEventFlag(i); localHr->setMeanThetaPad1(t1); localHr->setMeanThetaPad2(t2); localHr->setSecMult(secM); localHr->setMeanChargeSec(meanCS); localHr->setEvtNum(evtNum); } } else{ // cout<<"update local maxima "<setMeanThetaLoc1(t1); localHr->setMeanThetaLoc2(t2); } } Bool_t HClusterSelector::multihit(Int_t nRow, Int_t nCol, Int_t nSector, HLocation& fLoc) { //this memberfunction is required for hrichlocalmaxsim class return kTRUE; }