#include "hitofcalibrater.h" #include "hitofdef.h" #include "hdebug.h" #include "hades.h" #include "hiterator.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hdetector.h" #include "hitofdetector.h" #include "hitofraw.h" #include "hevent.h" #include "hpartialevent.h" #include "hcategory.h" #include "hmatrixcategory.h" #include "hrecevent.h" #include "hlocation.h" #include "hitofcalpar.h" #include "hitofcal.h" #include "hitofcaldebug.h" #include "hitofcalsim.h" #include "hstartdef.h" #include "hstart2hit.h" #include "TRandom.h" #include #include #include //_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////////////// // // HiTofCalibrater calibrates raw iTof data and puts output // values into cal data category // ///////////////////////////////////////////////////////////////////// ClassImp(HiTofCalibrater) HiTofCalibrater::HiTofCalibrater(const Text_t *name, const Text_t *title, Bool_t t0reco) : HReconstructor(name, title) { fCalCat = 0; fRawCat = 0; fStartHitCat = 0; fpiTofCalPar = NULL; fsimulation = kFALSE; fIsUsedT0 = t0reco; fLoc.set(3, -1, -1, -1); doDebug = kFALSE; } Bool_t HiTofCalibrater::init(void) { if (gHades->getEmbeddingMode() != 0 && doDebug) doDebug = kFALSE; // debug during embedding not supported HiTofDetector *itofdet = (HiTofDetector *)gHades->getSetup()->getDetector("iTof"); if (!itofdet) { Error("init()", "No iTof detector in setup!"); return kFALSE; } fRawCat = gHades->getCurrentEvent()->getCategory(catiTofRaw); if (!fRawCat) { Warning("init()", "Can not retrieve catiTofRaw!"); } fCalCat = gHades->getCurrentEvent()->getCategory(catiTofCal); if (!fCalCat) { if (gHades->getEmbeddingMode() != 0) { fCalCat = itofdet->buildMatrixCategory("HiTofCalSim"); } else { if(!doDebug)fCalCat = itofdet->buildCategory(catiTofCal); else fCalCat = itofdet->buildMatrixCategory("HiTofCalDebug",1.0); } if (!fCalCat) { Error("init()", "Can not build catiTofCal!"); return kFALSE; } else { gHades->getCurrentEvent()->addCategory(catiTofCal, fCalCat, "iTof"); } } fpiTofCalPar = (HiTofCalPar *)gHades->getRuntimeDb()->getContainer("iTofCalPar"); // Decide whether we are running for simulation or real data (also useful for embedding mode!!!) HCategory *catKin = gHades->getCurrentEvent()->getCategory(catGeantKine); if (catKin) fsimulation = kTRUE; else fsimulation = kFALSE; // Get Start Hit category. If StartHit is not defined or the start detector // is not in the setup a Warning is displayed and fStartHitCat is set to 0 fStartHitCat = gHades->getCurrentEvent()->getCategory(catStart2Hit); if (!fStartHitCat) { Warning("init", "Start Hit level not defining: setting start time to 0"); } return kTRUE; } Int_t HiTofCalibrater::execute(void) { Float_t startTime = 0; fLoc.set(3, -1, -1, -1); //-------------------------------------------- // startime handling if (!fIsUsedT0) { if (fStartHitCat) { HStart2Hit *h = NULL; if ((h = (HStart2Hit *)fStartHitCat->getObject(0)) != NULL) { startTime = h->getTime(); } else { startTime = 0.0; } } else { startTime = 0.0; } } else { startTime = 0.0; } //-------------------------------------------- if (fRawCat) { HiTofRaw *raw = 0; HiTofCal *cal = 0; HiTofCalDebug *calDb = 0; Float_t calTime = 0.; Float_t fastTime = 10000; Float_t sumTime = 0.; Int_t nTime = 0; Float_t calELoss = 0.; Float_t sumELoss = 0.; for (Int_t i = 0; i < fRawCat->getEntries(); i++) { raw = (HiTofRaw *)fRawCat->getObject(i); if (!raw) continue; fLoc[0] = raw->getSector(); fLoc[1] = raw->getModule(); fLoc[2] = raw->getCell(); if (fLoc[0] == -1 && fLoc[1] == -1 && fLoc[2] == -1) continue; cal = (HiTofCal *)fCalCat->getSlot(fLoc); if (gHades->getEmbeddingMode() == 0 || fsimulation == kFALSE) { if(!doDebug) cal = new (cal) HiTofCal; else { calDb = new (cal) HiTofCalDebug; cal = (HiTofCal*)calDb; } } else { cal = new (cal) HiTofCalSim; } cal->setAddress(fLoc[0], fLoc[1], fLoc[2]); if (cal != NULL) { fastTime = 10000.; sumTime = 0.; sumELoss = 0.; nTime = 0; for (Int_t j = 0; j < NSIMP; j++) // 12 SiMP channels used for Time, MeanTime and Eloss { if (raw->getTime(j) > DEFVAL) // unpacker gave us something for this channel { calELoss = fpiTofCalPar->calibrateCharge (fLoc[0], fLoc[1], fLoc[2], j, raw->getWidth(j)); calTime = fpiTofCalPar->calibrateTime_walkcorr(fLoc[0], fLoc[1], fLoc[2], j, raw->getTime (j),calELoss); calTime -= startTime; if(doDebug){ calDb->setCalTime(j, calTime); calDb->setCalWidth(j, calELoss); } if (calTime < fastTime) fastTime = calTime; // TODO: maybe would not be that hard to check if there is some cluster of channels giving similar time but one (noisy) channel can have smaller time => this will be used now!! sumTime += calTime; sumELoss += calELoss; nTime++; } } cal->setTime(fastTime); cal->setMeanTime(sumTime / ((Float_t)nTime)); cal->setEloss(sumELoss / ((Float_t)nTime)); cal->setMultiplicity(nTime); // reset values for summed channels: nTime = 0; sumELoss = 0.; for (Int_t j = NSIMP; j < NCHAN; j++) // 3 summed channels mainly for ToT measurement -> ElossSummed { if (raw->getTime(j) > DEFVAL) // unpacker gave us something for this channel { calELoss = fpiTofCalPar->calibrateCharge(fLoc[0], fLoc[1], fLoc[2], j, raw->getWidth(j)); if(doDebug){ calTime = fpiTofCalPar->calibrateTime(fLoc[0], fLoc[1], fLoc[2], j, raw->getTime(j)); // not used!! calDb->setCalTime(j, calTime); calDb->setCalWidth(j, calELoss); } sumELoss += calELoss; nTime++; } } cal->setElossSummed(sumELoss / ((Float_t)nTime)); } } } return 0; }