//_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////// // // HFRpcCalibrater: // // Calibrates all fired cells in PionTrackerRaw category and fills // the PionTrackerCal category // //////////////////////////////////////////////////////////////// #include "hfrpccalibrater.h" #include "hades.h" #include "hcategory.h" #include "hdebug.h" #include "hevent.h" #include "hfrpccal.h" #include "hfrpccalpar.h" #include "hfrpcdetector.h" #include "hfrpcdigipar.h" #include "hfrpcgeompar.h" #include "hfrpcraw.h" #include "hfrpcstrippar.h" #include "hgeomcompositevolume.h" #include "hgeomvector.h" #include "hgeomvolume.h" #include "hiterator.h" #include "hrun.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hstart2hit.h" #include "hstartdef.h" #include #include #include #include #include using namespace std; HFRpcCalibrater::HFRpcCalibrater() : pRawCat(nullptr), pCalCat(nullptr), pStartHitCat(nullptr), iter(nullptr) { // default constructor } HFRpcCalibrater::HFRpcCalibrater(const Text_t *name, const Text_t *title) : HReconstructor(name, title), pRawCat(nullptr), pCalCat(nullptr), pStartHitCat(nullptr), iter(nullptr) { // constructor } HFRpcCalibrater::~HFRpcCalibrater() { // destructor deletes the iterator on the raw category if (nullptr != iter) { delete iter; iter = nullptr; } } Bool_t HFRpcCalibrater::init() { HFRpcDetector *det = (HFRpcDetector *)gHades->getSetup()->getDetector("FRpc"); if (!det) { Error("init", "No FRpc found."); return kFALSE; } // retrieve the parameter container pCalPar = (HFRpcCalPar *)gHades->getRuntimeDb()->getContainer("FRpcCalPar"); if (!pCalPar) { Error("HFRpcDigitizer::init()", "Parameter container for FRPC calibration not created"); return kFALSE; } pStripPar = (HFRpcStripPar *)gHades->getRuntimeDb()->getContainer("FRpcStripPar"); if (!pStripPar) { Error("HFRpcDigitizer::init()", "Parameter container for FRPC strip calibration not created"); return kFALSE; } pDigiPar = (HFRpcDigiPar *)gHades->getRuntimeDb()->getContainer("FRpcDigiPar"); if (!pDigiPar) { Error("HFRpcDigitizer::init()", "Parameter container for FRPC digitizer not created"); return kFALSE; } pGeomPar = (HFRpcGeomPar *)gHades->getRuntimeDb()->getContainer("FRpcGeomPar"); if (!pGeomPar) { Error("HFRpcDigitizer::init()", "Parameter container for FRPC geometry not created"); return kFALSE; } pRawCat = gHades->getCurrentEvent()->getCategory(catFRpcRaw); if (!pRawCat) { Warning("init()", "HFRpcRaw category not available!"); } pCalCat = det->buildCategory(catFRpcCal); if (!pCalCat) return kFALSE; pStartHitCat = (HCategory *)(((HEvent *)(gHades->getCurrentEvent()))->getCategory(catStart2Hit)); if (pStartHitCat == nullptr) { Info("HFRpcCalibrater::init()", "No Start2Hit category, no Start time correction\n"); } if (pRawCat) iter = (HIterator *)pRawCat->MakeIterator(); loc.set(2, 0, 0); fActive = kTRUE; for (Int_t s = 0; s < FRPC_MAX_SECTORS; ++s) for (Int_t c = 0; c < FRPC_MAX_STRIPS; ++c) frpcCellsLab[s][c] = nullptr; return kTRUE; } Bool_t HFRpcCalibrater::reinit() { for (Int_t s = 0; s < FRPC_MAX_SECTORS; ++s) { HModGeomPar *fmodgeom = pGeomPar->getModule(s); // If module/sector is disabled in geometry, skip it. if (!fmodgeom) continue; HGeomTransform labTrans = fmodgeom->getLabTransform(); cosa[s] = labTrans.getRotMatrix().getElement(0, 0); sina[s] = labTrans.getRotMatrix().getElement(1, 0); HGeomCompositeVolume *fMod = fmodgeom->getRefVolume(); HFRpcCalParSec &p_sec = (*pCalPar)[s]; for (Int_t c = 0; c < FRPC_MAX_STRIPS; ++c) { HGeomVolume *fVol = fMod->getComponent(c); if (frpcCellsLab[s][c] == nullptr) frpcCellsLab[s][c] = new HGeomVector; HGeomVector *p = frpcCellsLab[s][c]; *p = fVol->getTransform().getTransVector(); *p = labTrans.transFrom(*p); HFRpcCalParCell &p_chan = p_sec[c]; offset_time[s][c] = p_chan.getTimeOffset(); offset_pos[s][c] = p_chan.getPosOffset(); } } strip_length = pDigiPar->getStripLength(); avg_prop_speed = pDigiPar->getTimeProp(); return kTRUE; } Int_t HFRpcCalibrater::execute() { Float_t start_time = 0.0; if (pStartHitCat && pStartHitCat->getEntries() > 0) { HStart2Hit *pStartHit = (HStart2Hit *)pStartHitCat->getObject(0); if (pStartHit && pStartHit->getFlag()) start_time = pStartHit->getTime(); } if (pRawCat) { // calibrates all fired cells [strip,module] HFRpcRaw *pRaw = nullptr; // Fill cal category iter->Reset(); while ((pRaw = (HFRpcRaw *)iter->Next()) != 0) // interation over fired cells { Char_t sec = 0; Char_t col = 0; Char_t strip = 0; pRaw->getAddress(sec, col, strip); // If sector is disabled in setup, skip it. if (!frpcCellsLab[(int)sec][0]) continue; Int_t cstrip = strip * FRPC_MAX_COLUMNS + col; loc[0] = sec; loc[1] = cstrip; Int_t n_n = pRaw->getHitsNumN(); Int_t n_f = pRaw->getHitsNumF(); // Loop over all pairs of N and F hits. If the deltaT is larger than 8 ns // (for safety assume 10 ns) then this is not correct pair. // Also check for Q and get rid of Q below 0. HFRpcCalParSec &p_sec = (*pCalPar)[sec]; HFRpcCalParCell &p_chan = p_sec[cstrip]; Float_t thr_n = p_chan.getQthresholdN(); Float_t thr_f = p_chan.getQthresholdF(); Float_t rawTimeN = 0.F; Float_t rawTimeF = 0.F; Float_t rawChargeN = 0.F; Float_t rawChargeF = 0.F; Int_t i_f = 0; // must be independet for (Int_t i_n = 0; i_n < n_n; ++i_n) { pRaw->getTimeAndWidthN(i_n, rawTimeN, rawChargeN); rawChargeN -= thr_n; if (rawChargeN < 0) continue; for (; i_f < n_f; ++i_f) { pRaw->getTimeAndWidthF(i_f, rawTimeF, rawChargeF); rawChargeF -= thr_f; if (rawChargeF < 0) continue; // find delta T and if to large, then make decision if (fabs(rawTimeF - rawTimeN) > 13.) { if (rawTimeN < rawTimeF) break; // N is to early, break loop over F and go to the next N continue; // F is to early, go to next F } // proper pair is found, process it as call goto after_pair_found; // (RL) I add it with full awarness of using goto } } continue; after_pair_found: if (sec >= 0) { HFRpcCal *pCal = (HFRpcCal *)pCalCat->getObject(loc); if (!pCal) // should be no object under location loc yet { pCal = (HFRpcCal *)pCalCat->getSlot(loc); if (pCal) // there should be space reserved for the slot { pCal = new (pCal) HFRpcCal; pCal->setAddress(loc[0], loc[1]); } else { Error("execute()", "Can't get slot mod=%i, lay=%i, cell=%d", sec, col, strip); return -1; } } else { Error("execute()", "Slot already exists for mod=%i, lay=%i, cell=%d", sec, col, strip); return -1; } Float_t calTimeN = rawTimeN - start_time; Float_t calTimeF = rawTimeF - start_time; // set calibrated data pCal->reconstructHits(calTimeN, calTimeF, rawChargeN, rawChargeF, frpcCellsLab[(int)sec][cstrip]->Z(), p_chan.getPropCorr() * avg_prop_speed, strip_length, offset_pos[(int)sec][cstrip], offset_time[(int)sec][cstrip], frpcCellsLab[(int)sec][cstrip], cosa[(int)sec], sina[(int)sec], p_chan.getTwcPar0(), p_chan.getTwcPar1(), p_chan.getTwcPar2()); } } } return 0; }