//*-- Author : Rafal Lalik //*-- Created : 10.01.2017 //_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////// // HFRpcHitFinder // // This class searches for hits in the Forward Rpc detector data // // Produce HFRpcHit // ///////////////////////////////////////////////////////////// #include "hfrpchitfinder.h" #include "hades.h" #include "hcategory.h" #include "hdebug.h" #include "hevent.h" #include "hfrpccluster.h" #include "hfrpcdetector.h" #include "hfrpcgeompar.h" #include "hfrpchit.h" #include "hfrpchitfinderpar.h" #include "hgeantfrpc.h" #include "hgeantkine.h" #include "hruntimedb.h" #include "hspectrometer.h" using namespace std; // #define VERBOSE_MODE 1 struct RpcHit { Int_t cluster; Float_t x, y, z, tof; Int_t track; }; HFRpcHitFinder::HFRpcHitFinder() { // default constructor initVariables(); } HFRpcHitFinder::HFRpcHitFinder(const Text_t *name, const Text_t *title) : HReconstructor(name, title) { // constructor initVariables(); } void HFRpcHitFinder::initVariables() { // initialize the variables in constructor pFRpcClusCat = 0; pFRpcHitCat = 0; fLoc.setNIndex(1); fLoc.set(1, 0, 0); } Bool_t HFRpcHitFinder::init() { // initializes the task // find the Forward detector in the HADES setup HFRpcDetector *pFRpc = (HFRpcDetector *)(gHades->getSetup()->getDetector("FRpc")); if (!pFRpc) { Error("FRpcDigitizer::init", "No Forward Detector found"); return kFALSE; } // get the Cal category pFRpcClusCat = gHades->getCurrentEvent()->getCategory(catFRpcClus); if (!pFRpcClusCat) { Error("HFRpcHitFinder::init()", "Clus category not found"); return kFALSE; } // build the Calibration category pFRpcHitCat = pFRpc->buildCategory(catFRpcHit, kTRUE); if (!pFRpcHitCat) { Error("HFRpcHitFinder::init()", "Hit category not created"); return kFALSE; } // create the parameter container pFRpcHitFinderPar = (HFRpcHitFinderPar *)gHades->getRuntimeDb()->getContainer("FRpcHitFinderPar"); if (!pFRpcHitFinderPar) { Error("HFRpcHitFinder::init()", "Parameter container for hit finder not created"); return kFALSE; } return kTRUE; } Bool_t HFRpcHitFinder::reinit() { #ifdef VERBOSE_MODE pFRpcHitFinderPar->print(); #endif fMatchRadius = pFRpcHitFinderPar->getMatchRadius(); fMatchTime = pFRpcHitFinderPar->getMatchTime(); return kTRUE; } Int_t HFRpcHitFinder::execute() { HFRpcCluster *clus = 0; #ifdef VERBOSE_MODE Int_t cnt = 0; printf("<<--- RPC: VERBOSE_MODE ON ---------------------->>\n"); #endif std::vector hits[FRPC_MAX_SECTORS]; std::vector has_pair[FRPC_MAX_SECTORS]; Float_t x = 0.0, y = 0.0, z = 0.0, tof = -1.0; // for Clus Int_t entries = pFRpcClusCat->getEntries(); for (Int_t i = 0; i < entries; ++i) { clus = (HFRpcCluster *)pFRpcClusCat->getObject(i); if (!clus) continue; x = clus->getX(); y = clus->getY(); z = clus->getZ(); tof = clus->getTof(); // FIXME needed for matching // RpcHit rpch; // rpch.x = x; // rpch.y = y; // rpch.z = z; // rpch.tof = tof; // // hits[(Int_t)sector].push_back(rpch); // has_pair[(Int_t)sector].push_back(0); fillHit(x, y, z, tof, i, -1); // FIXME remove for matching } return 0; // FIXME matching must be done for (UInt_t i = 0; i < hits[0].size(); ++i) { RpcHit h1 = hits[0][i]; for (UInt_t j = 0; j < hits[1].size(); ++j) { RpcHit h2 = hits[1][j]; Float_t dx = h2.x - h1.x; Float_t dy = h2.y - h1.y; Float_t radius = sqrt(dx * dx + dy * dy); Float_t dt = h2.tof - h1.tof; if (radius < fMatchRadius * 10. and dt < fMatchTime) { Float_t n_x = (h1.x + h2.x) / 2.0; Float_t n_y = (h1.y + h2.y) / 2.0; Float_t n_z = (h1.z + h2.z) / 2.0; // avg_z; Float_t n_tof = (h1.tof + h2.tof) / 2.0; fillHit(n_x, n_y, n_z, n_tof, h1.cluster, h2.cluster); ++has_pair[0][i]; ++has_pair[1][j]; } } } for (Int_t m = 0; m < FRPC_MAX_SECTORS; ++m) { for (UInt_t i = 0; i < hits[m].size(); ++i) { if (0 == has_pair[m][i]) { RpcHit h = hits[m][i]; fillHit(h.x, h.y, h.z, h.tof, h.cluster, -1); } } } return 0; } bool HFRpcHitFinder::fillHit(Float_t x, Float_t y, Float_t z, Float_t tof, Int_t hit1, Int_t hit2) { Int_t h = pFRpcHitCat->getEntries(); fLoc[0] = h; // hit nr HFRpcHit *hit = (HFRpcHit *)pFRpcHitCat->getObject(fLoc); if (hit == nullptr) { hit = (HFRpcHit *)pFRpcHitCat->getSlot(fLoc); hit = new (hit) HFRpcHit; } if (hit) { hit->setHit(x, y, z, tof, hit1, hit2); #ifdef VERBOSE_MODE hit->print(); printf("\n"); #endif } else return kFALSE; return kTRUE; }