// File: hrichlocalmaxcal.cc // // // //***************************************************************************** // this class is build to analyse and select the big ring events from the // online efficiency mesurement (OEM) of the rich. It looks for photon hits // in cal container and safes them to lokal container. For a local maximum out // of 5 or 9 neighbours pad it calculates the emphasisangles out of the charges // and safes it together with the sum of the charges to the central pad. After // this the emphasisangles for each big ring is calculated out of the // emphasisangle for the photonhits. If the rings in one event is like the // specifications, a flag is set to local container. For each pad of one ring // the energy of the pad out of the simulation with the same beamenergy and // particle is saved. //***************************************************************************** // #include "hrichlocalmaxcal.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 "hrichlocal.h" #include "hdebug.h" #include "hades.h" #include "richdef.h" #include "hrichgeometrypar.h" #include "hrichlocalmaxheader.h" ClassImp(HRichLocalMaxCal) HRichLocalMaxCal::HRichLocalMaxCal(const Text_t *name,const Text_t *title, Int_t pads, Int_t hitMin, Int_t sector, Float_t minTheta1, Float_t maxTheta1, Float_t minTheta2, Float_t maxTheta2, const Char_t energyFileName[128],Int_t secEdge1, Int_t secEdge2,Int_t minHitsecEdge1, Int_t minHitsecEdge2) : HReconstructor(name,title) { edgesector1 = secEdge1; edgesector2 = secEdge2; minHitedgesector1 =minHitsecEdge1; minHitedgesector2 = minHitsecEdge2; padNumber = pads; minHit = hitMin; fIter = NULL; fIter1 = NULL; thetaMin1 = minTheta1; thetaMax1 = maxTheta1; thetaMin2 = minTheta2; thetaMax2 = maxTheta2; shadowSector = sector; eventNr = 0; localEventNr = 1; strcpy(filename, energyFileName); i = 0; j = 0; } HRichLocalMaxCal::~HRichLocalMaxCal(void) { if (fIter) delete fIter; if (fIter1) delete fIter1; } Bool_t HRichLocalMaxCal::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(); fLocalCat = gHades -> getCurrentEvent() -> getCategory(catRichLocal); if (!fLocalCat) { fLocalCat = pRichDet -> buildCategory(catRichLocal); if (!fLocalCat) return kFALSE; else gHades -> getCurrentEvent() -> addCategory(catRichLocal, fLocalCat,"Rich"); } fIter1 = (HMatrixCatIter*) getLocalCat() -> MakeIterator(); tCharge = new TNtuple("tCharge","tCharge","padNr:q0:q1:q2:q3:q4:q5:q6:q7:q8:qSum:iSec:iEvtNr"); tCharge -> SetAutoSave(); HRuntimeDb* rtdb = gHades -> getRuntimeDb(); HRichGeometryPar *pGeomPar = (HRichGeometryPar*) rtdb -> getContainer("RichGeometryParameters"); if (pGeomPar == NULL) { pGeomPar = new HRichGeometryPar; rtdb -> addContainer(pGeomPar); } setGeometryPar(pGeomPar); if (pGeomPar == NULL) return kFALSE; energyfile(); return kTRUE; } Bool_t HRichLocalMaxCal::finalize() { tCharge -> Write(); energyout(); return kTRUE; } HRichLocalMaxCal& HRichLocalMaxCal::operator=(HRichLocalMaxCal &c) { return c; } Int_t HRichLocalMaxCal::execute() { // cout<<" executing hrichlocalmaxcal "< Reset(); count1 = count2 = 0; fTheta1 = fTheta2 = 0; i = 0; //fill the matrixes with data from cal container while ((pCal = (HRichCal *) fIter -> Next())) { loc = fIter -> getLocation(); fillmatrix(loc); i++; } //if the counter i == 0 there is no event copied to the matrix //cal must be empty!!! if (i == 0) { cout<<"fillmatrix false !!!"< Reset(); i = 0; count1 = count2 = 0; fTheta1 = fTheta2 = 0; if (hitControl == kTRUE) { //remove me //calculates the local maxima for a group of 9 or 5 pads //theta and phi angle is not longer the centre of one pad //safes the data to local container //the charge of the local group of pads is added to the central pad while ((pCal = (HRichCal*) fIter -> Next())) { loc = fIter -> getLocation(); localmaxcal(loc); i++; } //cout<<" theta1loc "< Reset(); i = 0; //safes the flag of the rings to local container while ((pLocal = (HRichLocal*) fIter1 -> Next())) { loc2 = fIter1 -> getLocation(); localanglecut(loc2); i++; } //if the counter 1 == 0 thre is no event in local container if (i == 0) { cout<<"local false !!!"< getObject(fLoc); iCol = cal -> getCol(); iRow = cal -> getRow(); iSector = cal -> getSector(); HRichPad *pad = ((HRichGeometryPar*) fGeometryPar) -> getPadsPar()->getPad(iCol,iRow); if (cal) { mHit[iSector][iRow][iCol] = 1; mCharge[iSector][iRow][iCol] = cal -> getCharge(); meanCharge[iSector]= meanCharge[iSector]+mCharge[iSector][iRow][iCol]; mTheta[iSector][iRow][iCol] = pad -> getTheta(); mPhi[iSector][iRow][iCol] = pad -> getPhi(iSector); //cout<<" charge "< getTheta())>thetaMin1&& (pad -> getTheta()) getTheta())>thetaMin2&&(pad -> getTheta()) getObject(fLoc); HRichLocal *local = NULL; iCol = cal -> getCol(); iRow = cal -> getRow(); iSector = cal -> getSector(); // eventNr = cal -> getEventNr(); nPad = 0; sumTheta = 0; sumPhi = 0; sumCharge = 0; HRichPad *pPad = ((HRichGeometryPar*) fGeometryPar) -> getPadsPar()->getPad(iCol,iRow); // cout<<" new pad analyzed +++++++++++++++++++++++"< getPadActive())&& //selects if the central pad is the local maximum for 9 pads // or for 5 pads (flagMax>0)){ Int_t k = 0; for (jRow = iRow-1; jRow < iRow+2; jRow++) { for (jCol = iCol-1; jCol < iCol+2; jCol++) { nPad = nPad + mHit[iSector][jRow][jCol]; fCharge[k] = 0; fCharge[k] = mCharge[iSector][jRow][jCol]; k++; } } //cout<<" photon found "< getSlot(fLoc); if ((local) && (iCol != 0)) { local = new(local) HRichLocal; local -> setRow(iRow); local -> setCol(iCol); local -> setSector(iSector); local -> setEventNr(eventNr); local -> setAddress(cal -> getAddress()); local -> setLocalEventNr(localEventNr); local -> setLocalCharge(sumCharge); local -> setLocalTheta(sumTheta); local -> setLocalPhi(sumPhi); local -> setLocalEnergy(energyset(iRow,iCol,iSector)); local -> setPadNr(nPad); local -> setFlagMax(flagMax); // cout<<" col is "<getSector()<getLocalEnergy()==0) cout<<"energy is 0 ,theta is"<< local ->getLocalTheta()<getLocalEnergy()<<" theta is "<getLocalTheta()<thetaMin1&& sumTheta fTheta1 "<thetaMin2&& sumTheta Fill(nPad,fCharge[0],fCharge[1],fCharge[2], fCharge[3],fCharge[4],fCharge[5],fCharge[6], fCharge[7],fCharge[8],sumCharge,iSector,localEventNr); } return kTRUE; } Bool_t HRichLocalMaxCal::localanglecut(HLocation& fLoc) { HRichLocal *local = NULL; local = (HRichLocal *)fLocalCat -> getObject(fLoc); if ((local -> getLocalTheta() < thetaMax1) && (local -> getLocalTheta() > thetaMin1)) { if ((local) && (local -> getCol() != 0)) { local -> setRing(1); } } if ((local -> getLocalTheta() > thetaMin2) && (local -> getLocalTheta() < thetaMax2)) { if ((local) && (local -> getCol() != 0)) { local -> setRing(2); } } else local -> setRing(0); return kTRUE; } Bool_t HRichLocalMaxCal::resetmatrix() { for (iSector = 0; iSector < 6; iSector++) { meanCharge[iSector]=0; for (iRow = 0; iRow < 90; iRow++) { for (iCol = 0; iCol < 92; iCol++) { mHit[iSector][iRow][iCol] = 0; mCharge[iSector][iRow][iCol] = 0; mTheta[iSector][iRow][iCol] = 0; mPhi[iSector][iRow][iCol] = 0; mHit2[iSector][iRow][iCol] = 0; } } } return kTRUE; } Bool_t HRichLocalMaxCal::hitcontrol() { for (iSector = 0; iSector < 6; iSector++) { sumHit[iSector] = 0; doubleHit[iSector] = 0; //counts hits in each sector for (iRow = 0; iRow < 90; iRow++) { for (iCol = 0; iCol < 92; iCol++) { if (mHit[iSector][iRow][iCol] == 1) { sumHit[iSector]++; //counts the hits were pads where active in the previous evt. if (mHit2[iSector][iRow][iCol] == 1) { doubleHit[iSector]++; } } mHit2[iSector][iRow][iCol] = mHit[iSector][iRow][iCol]; } } if(sumHit[iSector]) meanCharge[iSector] = meanCharge[iSector]/sumHit[iSector]; } i = 0; hitControl = kFALSE; //the event is rejected if there is an after burning sector with an hit multiplicity higher than the threshold set in the macro. The shadow sector is excluded from the selection. for (iSector = 0; iSector < 6; iSector++) { if ((doubleHit[iSector] <= sumHit[iSector] / 2 && sumHit[iSector]>minHit) || (iSector == shadowSector)) {//$$ i++; } } // cout<<" index "<=3 && sumHit[edgesector1]>minHitedgesector1&& sumHit[edgesector2]>minHitedgesector2 ) { hitControl = kTRUE; updateHeaders(fTheta1/count1,fTheta2/count2,1,sumHit,meanCharge,eventNr); } else { updateHeaders(0,0,0,sumHit,meanCharge,eventNr); } return kTRUE; } void HRichLocalMaxCal::updateHeaders(Float_t t1, Float_t t2,Int_t i,Float_t *secM,Float_t *meanCS,Int_t evtNum){ HRichLocalMaxHeader *localHr = NULL; HLocation loc; loc.set(1,0); localHr = (HRichLocalMaxHeader*)fLocalCatHr->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 HRichLocalMaxCal::energyfile() { pEnergyLockup = new TFile(filename); for (iSector = 0; iSector < 6; iSector++) { sprintf(energyName,"pEnergySim%d",iSector); pEnergySim[iSector] = (TH2F*) pEnergyLockup -> Get(energyName); } return kTRUE; } Bool_t HRichLocalMaxCal::multihit(Int_t nRow, Int_t nCol, Int_t nSector, HLocation& fLoc) { //this memberfunction is required for hrichlocalmaxsim class return kTRUE; } Bool_t HRichLocalMaxCal::energyout() { //this memberfunction is required for hrichlocalmaxsim class return kTRUE; } Float_t HRichLocalMaxCal::energyset(Int_t nRow, Int_t nCol, Int_t nSector) { energy = 0.; // cout<<" in exp energyset "< GetCellContent(nRow,nCol) != 0) { energy = pEnergySim[nSector] -> GetCellContent(nRow,nCol); return energy; } //if there is no photonenergyinformation for this pad it is //calculated by the information out of the nightbourpads if ((pEnergySim[nSector] -> GetCellContent(nRow,nCol-1) != 0) && (pEnergySim[nSector] -> GetCellContent(nRow,nCol+1) != 0)) { energy = (pEnergySim[nSector] -> GetCellContent(nRow,nCol-1) + pEnergySim[nSector] -> GetCellContent(nRow,nCol+1)) / 2; return energy; } if ((pEnergySim[nSector] -> GetCellContent(nRow-1,nCol) != 0) && (pEnergySim[nSector] -> GetCellContent(nRow+1,nCol) != 0)) { energy = (pEnergySim[nSector] -> GetCellContent(nRow-1,nCol) + pEnergySim[nSector] -> GetCellContent(nRow+1,nCol)) / 2; return energy; } if (pEnergySim[nSector] -> GetCellContent(nRow,nCol-1) != 0) { energy = pEnergySim[nSector] -> GetCellContent(nRow,nCol-1); return energy; } if (pEnergySim[nSector] -> GetCellContent(nRow,nCol+1) != 0) { energy = pEnergySim[nSector] -> GetCellContent(nRow,nCol+1); return energy; } if ((pEnergySim[nSector] -> GetCellContent(nRow,nCol-2) != 0) && (pEnergySim[nSector] -> GetCellContent(nRow,nCol+2) != 0)) { energy = (pEnergySim[nSector] -> GetCellContent(nRow,nCol-2) + pEnergySim[nSector] -> GetCellContent(nRow,nCol+2)) / 2; return energy; } if ((pEnergySim[nSector] -> GetCellContent(nRow-1,nCol) != 0) && (pEnergySim[nSector] -> GetCellContent(nRow-2,nCol) != 0)) { energy = 2 * pEnergySim[nSector] -> GetCellContent(nRow-1,nCol) - pEnergySim[nSector] -> GetCellContent(nRow-2,nCol); return energy; } if ((pEnergySim[nSector] -> GetCellContent(nRow+1,nCol) != 0) && (pEnergySim[nSector] -> GetCellContent(nRow+2,nCol) != 0)) { energy = 2 * pEnergySim[nSector] -> GetCellContent(nRow+1,nCol) - pEnergySim[nSector] -> GetCellContent(nRow+2,nCol); return energy; } if (pEnergySim[nSector] -> GetCellContent(nRow,nCol+2) != 0) { energy = (pEnergySim[nSector] -> GetCellContent(nRow,nCol+2)); return energy; } if (pEnergySim[nSector] -> GetCellContent(nRow,nCol-2) != 0) { energy = (pEnergySim[nSector] -> GetCellContent(nRow,nCol-2)); return energy; } return 0.; }