//*-- Created : 04/12/2009 by I.Koenig //_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////// // // HStart2Calibrater: // // Calibrates all fired cells in Start2Raw category and fills // the Start2Cal category // //////////////////////////////////////////////////////////////// #include "hades.h" #include "hcategory.h" #include "hdebug.h" #include "hrecevent.h" #include "hevent.h" #include "heventheader.h" #include "hiterator.h" #include "hruntimedb.h" #include "hrun.h" #include "htime.h" #include "hbeamtime.h" #include "hspectrometer.h" #include "hdatasource.h" #include "hstart2cal.h" #include "hstart2calibrater.h" #include "hstart2calpar.h" #include "hstart2detector.h" #include "hstart2raw.h" #include "hstartdef.h" #include #include #include #include using namespace std; ClassImp(HStart2Calibrater) Bool_t HStart2Calibrater::doCorrection = kTRUE; HStart2Calibrater::HStart2Calibrater(const Text_t *name, const Text_t *title) : HReconstructor(name, title) { // constructor rawCat = NULL; calCat = NULL; iter = NULL; calpar = NULL; runpar = NULL; correction.clear(); corrs.resize(384,0); setTimeWindow(-1000000,1000000); fVersion = 0; } HStart2Calibrater::~HStart2Calibrater(void) { //destructor deletes the iterator on the raw category if (NULL != iter) { delete iter; iter = NULL; } } void HStart2Calibrater::setCorrection(Bool_t corr) { // kTRUE = use HStart2CalRunPar (default) doCorrection = corr; } Bool_t HStart2Calibrater::init(void) { // gets the calibration parameter container // gets the Start2Raw category and creates the Start2Cal category // creates an iterator which loops over all fired cells in Start2Raw //--------------------------------------------------------- // switch the different beamtime versions HBeamTime::checkBeamTimeSettingByRunId("HStart2Calibrater::init()",kTRUE); // HADES::kUnknownBeam rejected Int_t year; HBeamTime::getYearFromRunID(year); if(year == 2022) { fVersion = 1; Info("init()", "Input file is detected from 2022. fVersion switch is set == 1 (LGAD cluster finder)."); } if(year > 2022) { if(year >= 2024) { // needs future fixes! HBeamTime fVersion = 2; Info("init()", "Input file is detected from 2024 or later. fVersion switch is set = 2 (LGAD cluster finder, 1/sqrt TW correction). If this is not desired, the code needs update"); } else { fVersion = 1; Info("init()", "Input file is detected after 2022. fVersion switch is set = 1 (LGAD cluster finder). If this is not desired, the code needs update"); } } //--------------------------------------------------------- calpar = (HStart2Calpar*)gHades->getRuntimeDb()->getContainer("Start2Calpar"); if (!calpar) return kFALSE; if(doCorrection){ runpar = (HStart2CalRunPar*)gHades->getRuntimeDb()->getContainer("Start2CalRunPar"); if (!runpar) return kFALSE; } HStart2Detector* det = (HStart2Detector*)gHades->getSetup()->getDetector("Start"); if (!det) { Error("init", "No Start Detector found."); return kFALSE; } rawCat = gHades->getCurrentEvent()->getCategory(catStart2Raw); if (!rawCat) { Warning("init()", "HStart2Raw category not available!"); } calCat = det->buildCategory(catStart2Cal); if (!calCat) return kFALSE; if(rawCat) iter = (HIterator*)rawCat->MakeIterator(); else iter = 0; loc.set(2, 0, 0); fActive = kTRUE; return kTRUE; } Bool_t HStart2Calibrater::reinit(void) { // gets the calibration parameter container if(doCorrection){ if (!runpar) return kFALSE; Int_t runID = gHades->getRuntimeDb()->getCurrentRun()->getRunId(); correction.clear(); runpar->getRun(runID,&correction); Int_t n = correction.getNVals(); corrs.resize(n,0); for(Int_t i=0;iReset(); while ((pRaw = (HStart2Raw *)iter->Next()) != 0) { pRaw->getAddress(mod, strip); loc[0] = mod; loc[1] = strip; if(!calpar->isInTable(mod,strip)) continue; if (loc[0] >= 0) { pCal = (HStart2Cal*)calCat->getObject(loc); // check for existing objects postboned after time cut // get the calibration parameters HStart2CalparCell &pPar = (*calpar)[mod][strip]; pPar.getData(parCellData); // loop over number of hits nhits = pRaw->getMultiplicity(); for (Int_t i = 0; i < nhits; i++) { // get raw time and width (only stored for 4 hits!) if (i < pRaw->getMaxMultiplicity()) { pRaw->getTimeAndWidth(i + 1, rawTime, rawWidth); } // else set dummy values (only for counting hits!) else { rawTime = 0.; rawWidth = 0.; } //--------------------------------------------------------- if(fVersion == 0){ // old beamtime kApr12,kJul14,kAug14,kMar19 // correct the time and width calTime = parCellData[0] * rawTime + parCellData[1] + corrs[loc[0]*16+loc[1]]; } else { // fVersion == 1 kFeb22 and later (future needs check of START structure) // new version LGAD Feb22 if(doCorrection && correction.getNVals() < 384){ Error("execute()","Your are running HStart2Calibrater with input hld from Feb22 or later, but the HStart2CalRunPar parameters are to few =%i ! Fix it!",correction.getNVals()); exit(1); } if(fVersion == 1) calTime = parCellData[0] * rawTime + parCellData[1] - corrs[ (loc[0]*96)+loc[1] ] - (corrs[ 192 + (loc[0]*96) + loc[1] ] * rawWidth); if(fVersion == 2){ if(loc[0]<2){ //START calTime = parCellData[0] * rawTime + parCellData[1] - corrs[ (loc[0]*96)+loc[1] ] - (corrs[ 192 + (loc[0]*96) + loc[1] ] * 1/sqrt(rawWidth)); } else {//VETO calTime = parCellData[0] * rawTime + parCellData[1]; } } } //--------------------------------------------------------- calWidth = parCellData[2] * rawWidth + parCellData[3]; if(calTime < lowcut || calTime > highcut) continue; // creation of object should be done only if // a valid cal in the time window exists if (!pCal) { pCal = (HStart2Cal *)calCat->getSlot(loc); if (pCal) { pCal = new(pCal) HStart2Cal; pCal->setAddress(loc[0], loc[1]); } else { Error("execute()", "Can't get slot mod=%i, chan=%i", loc[0], loc[1]); return -1; } } // fill cal hits bhits = pCal->setTimeAndWidth(calTime, calWidth); // check nhits if (i >= pRaw->getMaxMultiplicity() && bhits == kTRUE) { Error("execute()", "Start module %d strip %d : hit multiplicity > %d (unrecognized)", mod, strip, pRaw->getMaxMultiplicity()); } } } } return 0; }