//*-- Author : Rafal Lalik //*-- Created : 10.01.2017 //_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////// // HFRpcClusterFinder // // This class searches for clusters in the Forward Rpc detector data // // Produce HFRpcCluster // ///////////////////////////////////////////////////////////// #include "hfrpcclusterfinder.h" #include "frpcdef.h" #include "hades.h" #include "hcategory.h" #include "hdebug.h" #include "hevent.h" #include "hfrpccalsim.h" #include "hfrpccluster.h" #include "hfrpcdetector.h" #include "hfrpcgeompar.h" #include "hgeantfrpc.h" #include "hgeantkine.h" #include "hruntimedb.h" #include "hspectrometer.h" // #define VERBOSE_MODE 1 HFRpcClusterFinder::HFRpcClusterFinder() { // default constructor initVariables(); } HFRpcClusterFinder::HFRpcClusterFinder(const Text_t *name, const Text_t *title) : HReconstructor(name, title) { // constructor initVariables(); } void HFRpcClusterFinder::initVariables() { // initialize the variables in constructor pFRpcCalCat = 0; pFRpcClusterCat = 0; fLoc.setNIndex(1); fLoc.set(1, 0, 0); } Bool_t HFRpcClusterFinder::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 pFRpcCalCat = gHades->getCurrentEvent()->getCategory(catFRpcCal); if (!pFRpcCalCat) { Error("HFRpcClusterFinder::init()", "Cal category not found"); return kFALSE; } // build the Calibration category pFRpcClusterCat = pFRpc->buildCategory(catFRpcClus, kTRUE); if (!pFRpcClusterCat) { Error("HFRpcClusterFinder::init()", "Cluster category not created"); return kFALSE; } return kTRUE; } Bool_t HFRpcClusterFinder::reinit() { return kTRUE; } Int_t HFRpcClusterFinder::execute() { #ifdef VERBOSE_MODE printf("<<--- RPC: VERBOSE_MODE ON --- EVENT=%5d ------------->>\n", gHades->getCurrentEvent()->getHeader()->getEventSeqNumber()); #endif std::pair c1[FRPC_MAX_SECTORS][FRPC_MAX_STRIPS] = {{std::pair(nullptr, -1)}}; // Collect all strip hits Int_t entries = pFRpcCalCat->getEntries(); for (Int_t i = 0; i < entries; ++i) { HFRpcCal *cal = (HFRpcCal *)pFRpcCalCat->getObject(i); if (cal) { Char_t sector; // FRpc module number (0...3) Char_t strip; // FRpc layer number (0...31) cal->getAddress(sector, strip); c1[(Int_t)sector][(Int_t)strip] = std::make_pair(cal, i); } } /* Iterate over all strips and find pairs of neightbouring strip (strip diference == 1). * * Example of event with one double cluster, two close clusters, and single cluster. * The numbers are strip numbers. * * 1 3 5 7 9 11 13 15 17 * [ ][ ][**][ ][**][ ][ ][ ][**] * [ ][ ][**][ ][**][**][ ][**][ ] * 0 2 4 6 8 10 12 14 16 * * It iterates over strip number (j-variable) and checks whether j+1 exists. If no, there is * single cluster, otherwise is a double cluster. To avoid misrecognition of the second hit in * the cluster as a single cluster, the last-variable stores index of recently used the last * hit. If last == j, that means the j was already used. Example of case: * j=0..3 - nothing happens, last = -1 * j=4 - there is hit, j+1 (5) has also hit, so double cluster, set last=5 * j=5 - there is hit, there is no hit at j+1 (6) but j==last so j=5 is not a single hit * j=6..7 - nothing happens * j=8 - same like for j==4, last=9 * j=9 - there is hit as well as for j+1 (10) so add double hit; last=10 * j=10 - same like for j==5 * j=11..13 - nothing happens * j=14 - no hits for j+1(15) and last (10) != j (14) so add single hit * j=15..16 - nothing happens * j=17 - has hit, add as single hit, outside the loop * * Also time must be within 1 ns to match two stripes. */ for (Int_t i = 0; i < FRPC_MAX_SECTORS; ++i) { Int_t j = 0; Int_t last = -1; // last cal filled in cluster // j here is next srip number for (; j < FRPC_MAX_STRIPS - 1; ++j) { // if strip has no neighbour if (c1[i][j].first && !c1[i][j + 1].first && last != j) { Float_t x = c1[i][j].first->getX(); Float_t y = c1[i][j].first->getY(); Float_t z = c1[i][j].first->getZ(); Float_t tof = c1[i][j].first->getTof(); if (!fillCluster(x, y, z, tof, c1[i][j].second, -1)) Warning("HFRpcClusterFinder::execute()", "FRpc cluster cannot be filled."); last = j; } // if strip has neighbour if (c1[i][j].first && c1[i][j + 1].first) { // Check whether the time difference is within 1 ns, should itbe hardcoded? Float_t dtof = fabs(c1[i][j].first->getTof() - c1[i][j + 1].first->getTof()); if (dtof < 1.0) { Float_t x = (c1[i][j].first->getX() + c1[i][j + 1].first->getX()) / 2.0; Float_t y = (c1[i][j].first->getY() + c1[i][j + 1].first->getY()) / 2.0; Float_t z = (c1[i][j].first->getZ() + c1[i][j + 1].first->getZ()) / 2.0; Float_t tof = (c1[i][j].first->getTof() + c1[i][j + 1].first->getTof()) / 2.0; if (!fillCluster(x, y, z, tof, c1[i][j].second, c1[i][j + 1].second)) Warning("HFRpcClusterFinder::execute()", "FRpc cluster cannot be filled."); last = j + 1; } else { Float_t x = c1[i][j].first->getX(); Float_t y = c1[i][j].first->getY(); Float_t z = c1[i][j].first->getZ(); Float_t tof = c1[i][j].first->getTof(); if (!fillCluster(x, y, z, tof, c1[i][j].second, -1)) Warning("HFRpcClusterFinder::execute()", "FRpc cluster cannot be filled."); last = j; } } } // check the last possible strip if (last != j && c1[i][j].first) { Float_t x = c1[i][j].first->getX(); Float_t y = c1[i][j].first->getY(); Float_t z = c1[i][j].first->getZ(); Float_t tof = c1[i][j].first->getTof(); if (!fillCluster(x, y, z, tof, c1[i][j].second, -1)) Warning("HFRpcClusterFinder::execute()", "FRpc cluster cannot be filled."); } } return 0; } Bool_t HFRpcClusterFinder::fillCluster(Float_t x, Float_t y, Float_t z, Float_t tof, Int_t calidx1, Int_t calidx2) { fLoc[0] = pFRpcClusterCat->getEntries(); // next cluster nr HFRpcCluster *cluster = (HFRpcCluster *)pFRpcClusterCat->getObject(fLoc); if (cluster == nullptr) { cluster = (HFRpcCluster *)pFRpcClusterCat->getSlot(fLoc); cluster = new (cluster) HFRpcCluster; } if (cluster) { cluster->setCluster(x, y, z, tof, calidx1, calidx2); #ifdef VERBOSE_MODE cluster->print(); printf("\n"); #endif } else return kFALSE; return kTRUE; }