//_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////// // // HStsCalibrater: // // Calibrates all fired cells in PionTrackerRaw category and fills // the PionTrackerCal category // //////////////////////////////////////////////////////////////// #include "hstscalibrater.h" #include "hades.h" #include "hcategory.h" #include "hdebug.h" #include "hevent.h" #include "heventheader.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 "hstscal.h" #include "hstscalibraterpar.h" #include "hstscalpar.h" #include "hstsdetector.h" #include "hstsgeompar.h" #include "hstsraw.h" #include "hstsstatuspar.h" #include "stsdef.h" #include #include #include #include using namespace std; // raw category, cal category, iterator, cal parameter, run_id ClassImp(HStsCalibrater) HStsCalibrater::HStsCalibrater() : pRawCat(nullptr), pCalCat(nullptr), pStartHitCat(nullptr), iter(nullptr), pStatusPar(nullptr) { // default constructor } HStsCalibrater::HStsCalibrater(const Text_t *name, const Text_t *title) : HReconstructor(name, title), pRawCat(nullptr), pCalCat(nullptr), pStartHitCat(nullptr), iter(nullptr), pStatusPar(nullptr) { // constructor } HStsCalibrater::~HStsCalibrater() { // destructor deletes the iterator on the raw category if (nullptr != iter) { delete iter; iter = nullptr; } } Bool_t HStsCalibrater::init() { HStsDetector *det = (HStsDetector *)gHades->getSetup()->getDetector("Sts"); if (!det) { Error("init", "No Sts found."); return kFALSE; } pGeomPar = (HStsGeomPar *)gHades->getRuntimeDb()->getContainer("StsGeomPar"); if (!pGeomPar) return kFALSE; pStatusPar = (HStsStatusPar *)gHades->getRuntimeDb()->getContainer("StsStatusPar"); if (!pStatusPar) return kFALSE; pCalPar = (HStsCalPar *)gHades->getRuntimeDb()->getContainer("StsCalPar"); if (!pCalPar) { Error("HStsCalibrater::init()", "Parameter container for starws not created"); return kFALSE; } pCalibraterPar = (HStsCalibraterPar *)gHades->getRuntimeDb()->getContainer("StsCalibraterPar"); if (!pCalibraterPar) { Error("HStsCalibrater::init()", "Parameter container for calibrater not created"); return kFALSE; } pStartHitCat = gHades->getCurrentEvent()->getCategory(catStart2Hit); if (!pStartHitCat) Warning("init", "Start hit level not defined; setting start time to 0"); pRawCat = gHades->getCurrentEvent()->getCategory(catStsRaw); if (!pRawCat) { Warning("init()", "HStsRaw category not available!"); } pCalCat = det->buildCategory(catStsCal); if (!pCalCat) return kFALSE; if (pRawCat) iter = (HIterator *)pRawCat->MakeIterator(); loc.set(4, 0, 0); fActive = kTRUE; for (Int_t m = 0; m < STS_MAX_MODULES; ++m) for (Int_t l = 0; l < STS_MAX_LAYERS; ++l) for (Int_t c = 0; c < STS_MAX_CELLS; ++c) stsCellsLab[m][l][c] = nullptr; return kTRUE; } Bool_t HStsCalibrater::reinit() { for (Int_t m = 0; m < STS_MAX_MODULES; ++m) { for (Int_t l = 0; l < STS_MAX_LAYERS; ++l) { HModGeomPar *fmodgeom = pGeomPar->getModule(l, m); // If module/sector is disabled in geometry, skip it. if (!fmodgeom) continue; const HGeomTransform &labTrans = fmodgeom->getLabTransform(); // Geometry is rotated by Z (any deg) and Y (0 or 180 deg) axis only. Lets assign // cos(theta_y) == R (can be 1 or -1), and cos(theta_z) == C and sin(theta_z) == S, then // the rotation matrix is: // // | RC -S 0 | // | RS C 0 | // | 0 0 R | // // thus we take elements at 1,1 and 0,1 for cos and sin, respectively. cosa[m][l] = labTrans.getRotMatrix().getElement(1, 1); sina[m][l] = -fabs(labTrans.getRotMatrix().getElement(1, 0)); if (cosa[m][l] < 0) { cosa[m][l] = -cosa[m][l]; sina[m][l] = -sina[m][l]; } HGeomCompositeVolume *fMod = fmodgeom->getRefVolume(); for (Int_t c = 0; c < STS_MAX_CELLS; ++c) { HGeomVolume *fVol = fMod->getComponent(c); if (!fVol) break; if (stsCellsLab[m][l][c] == nullptr) stsCellsLab[m][l][c] = new HGeomVector; HGeomVector *p = stsCellsLab[m][l][c]; *p = fVol->getTransform().getTransVector(); *p = labTrans.transFrom(*p); } } } return kTRUE; } Int_t HStsCalibrater::execute() { if (!pRawCat) return 1; // calibrates all fired cells [strip,module] HStsRaw *pRaw = nullptr; // Getting start time. Only for real data! Float_t startTime = 0.0; if (pStartHitCat && pStartHitCat->getEntries() > 0) { HStart2Hit *pStartH = nullptr; // Start Hit object if ((pStartH = (HStart2Hit *)pStartHitCat->getObject(0)) != nullptr) { startTime = pStartH->getTime(); } } // Fill cal category iter->Reset(); while ((pRaw = (HStsRaw *)iter->Next()) != 0) // interation over fired cells { Char_t mod, lay, udconf; Int_t straw; pRaw->getAddress(mod, lay, straw, udconf); // If sector is disabled in setup, skip it. if (!stsCellsLab[(Int_t)mod][(Int_t)lay][0]) continue; loc[0] = mod; loc[1] = lay; loc[2] = straw; loc[3] = udconf; Int_t straw_status = pStatusPar->getStrawStatus(mod, lay, straw, udconf); if (straw_status) continue; // get data from raw category Float_t rawTime; Float_t rawWidth; pRaw->getTimeAndWidth(rawTime, rawWidth); if (rawWidth < 0.) continue; // correct the time and width HStsCalParCellKind &p_cell = (*pCalPar)[mod][lay][straw][udconf]; Float_t pars[11]; p_cell.getData(pars); Float_t calTime = rawTime - startTime - pars[0]; /* * We ask for window which is in range 0.0-WindowLow -//- TimeMax+WindowHigh * and reject all hits outside this window. */ if ((calTime < pCalibraterPar->getWindowLow()) or (calTime > pars[1] + pCalibraterPar->getWindowHigh())) continue; HStsCal *pCal = (HStsCal *)pCalCat->getObject(loc); if (!pCal) // should be no object under location loc yet { pCal = (HStsCal *)pCalCat->getSlot(loc); if (pCal) // there should be space reserved for the slot { pCal = new (pCal) HStsCal; pCal->setAddress(mod, lay, straw, udconf); } else { Error("execute()", "Can't get slot mod=%i, lay=%i, straw=%d, udconf=%d", mod, lay, straw, udconf); return -1; } } else { Error("execute()", "Slot already exists for mod=%i, lay=%i, straw=%d, udconf=%d", mod, lay, straw, udconf); return -1; } Float_t calCharge = rawWidth; Float_t calU = stsCellsLab[(int)mod][(int)lay][straw]->X() * cosa[(int)mod][(int)lay] + stsCellsLab[(int)mod][(int)lay][straw]->Y() * sina[(int)mod][(int)lay]; Float_t calZ = stsCellsLab[(int)mod][(int)lay][straw]->Z(); // set calibrated data pCal->setHit(calTime, calCharge, calU, calZ); } return 0; }