//_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////// // // HRich700Calibrater // // Class for reading HRich700Raw and filling HRichCal // // JoF (j.foertsch@uni-wuppertal.de) updated 18-Dec-2018 ///////////////////////////////////////////////////////////// #include "hades.h" #include "hcategory.h" #include "hevent.h" #include "heventheader.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hrichdetector.h" #include "hrich700raw.h" #include "hrichcal.h" #include "hrichcalsim.h" #include "hstart2hit.h" #include "hiterator.h" #include "hrich700calibrater.h" #include "hrich700thresholdpar.h" #include "richdef.h" #include "hstartdef.h" #include using namespace std; ClassImp(HRich700Calibrater) HRich700Calibrater::HRich700Calibrater(const Text_t* name, const Text_t* title) : HReconstructor(name,title) { // constructor fCalCat = NULL; fRawCat = NULL; fStartHitCat = NULL; fThresholds = NULL; fDoTimeCut = kTRUE; fUseSTART = kTRUE; iterRaw = NULL; } Bool_t HRich700Calibrater::init(void) { // creates the raw category and gets the pointer to the TRB3 lookup table HRichDetector* det = (HRichDetector*)gHades->getSetup()->getDetector("Rich"); if (!det) { Error("init", "No Rich Detector found."); return kFALSE; } fStartHitCat = gHades->getCurrentEvent()->getCategory(catStart2Hit); if (NULL == fStartHitCat) { Warning("init", "HStartHit category not found"); } fRawCat = gHades->getCurrentEvent()->getCategory(catRich700Raw); if (NULL == fRawCat) { Warning("init", "HRich700Raw category not found"); } fCalCat = gHades->getCurrentEvent()->getCategory(catRichCal); if (NULL == fCalCat) { if(gHades->getEmbeddingMode() == 0) { fCalCat = det->buildCategory(catRichCal); if (NULL == fCalCat) { Error("init", "Pointer to HRichCal category is NULL"); return kFALSE; } else { gHades->getCurrentEvent()->addCategory(catRichCal, fCalCat, "Rich"); } } else { fCalCat = det->buildMatrixCat("HRichCalSim", 1); if (NULL == fCalCat) { Error("init", "Can not build output category catRichCalSim, returning..."); return kFALSE; } else { gHades->getCurrentEvent()->addCategory(catRichCal, fCalCat, "Rich"); } } } iterRaw=(HIterator *)((HCategory*)fRawCat)->MakeIterator("native"); fRawLoc.set(2, 0, 0); fCalLoc.set(3, 0, 0, 0); // here second parameter to supress hits outside time and tot cuts per channel! fThresholds = (HRich700ThresholdPar*)(gHades->getRuntimeDb() ->getContainer("Rich700ThresholdPar")); if (!fThresholds) { Error("init", "No Pointer to parameter container Rich700ThresholdPar."); return kFALSE; } //////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// return kTRUE; } Bool_t HRich700Calibrater::reinit(void) { return kTRUE; } Int_t HRich700Calibrater::execute(void) { //calibration event if (gHades->isCalibration()) { return 1; } //scaler event if (gHades->getCurrentEvent()->getHeader()->getId() == 0xe) { return 1; } if(fRawCat && fCalCat){ Double_t starttime = 0; if(fStartHitCat && fUseSTART){ if(fStartHitCat->getEntries()>0){ HStart2Hit* start = (HStart2Hit*)fStartHitCat->getObject(0); starttime = start->getTime(); } } Int_t pmt,pix,sec,col,row; Double_t t1; Double_t tot; HRich700Raw* raw =0; iterRaw->Reset(); while ((raw=(HRich700Raw *)iterRaw->Next())!=0) { Int_t n = raw->getMultiplicity(); raw->getAddress(pmt,pix,sec,col,row); for (Int_t j = 0 ; j < n ; j ++) { const HRich700hit_t* hit = raw->getHit(j); if(0b11 != hit->fFlag) { continue; } t1 = hit->fLeadingEdgeTime - starttime; tot = hit->fToT; fRawLoc[0] = pmt; fRawLoc[1] = pix; // JAM here get pixel thresholds from parameter container: Double_t tmin=0, tmax=1.0e-6, totmin=1e-9, totmax=1e-8; // units here seconds like in the trb3 unpacker messages! HRich700PixelThreshold* pthres =fThresholds->getObject(fRawLoc); if(pthres) { if(pthres->getFlag() != 0) { continue; } tmin = pthres->getT_Min(); // use units ns from parameter container. tmax = pthres->getT_Max(); totmin = pthres->getTot_Min(); totmax = pthres->getTot_Max(); Int_t loc[3] = {sec,col,row}; if(loc[0]<0) continue; if(fDoTimeCut){ if( t1 tmax ) { continue; } if( tottotmax) { continue; } } addCalHitCharge(loc[0],loc[1],loc[2], t1, tot); //JoF: Here one could derive the charge of the hit from the ToT via ToTmin/max } else { Error("execute()", "Can't get threshold parameter for pmt=%i, pixel=%i, using precompileddefaults!", fRawLoc[0], fRawLoc[1]); continue; } } } } return 0; // kTRUE } Int_t HRich700Calibrater::addCalHitCharge(Int_t sector, Int_t col, Int_t row, Float_t time, Float_t tot) { fCalLoc[0] = sector; fCalLoc[1] = row; fCalLoc[2] = col; // from old rich unpacker: // loc.setOffset(col); // loc.setIndex(1, row); // loc.setIndex(0, fDataWord.sector); ////////////// HRichCalSim* calsim = 0; HRichCal* cal = static_cast(fCalCat->getObject(fCalLoc)); if (NULL == cal) { cal = static_cast(fCalCat->getSlot(fCalLoc)); if (NULL != cal) { // fill empty slot with new data instance: if(gHades->getEmbeddingMode() != 0){ cal = new (cal) HRichCalSim; calsim = static_cast (cal); if(!calsim->checkTrackId(gHades->getEmbeddingRealTrackId())) calsim->addTrackId(gHades->getEmbeddingRealTrackId()); } else { cal = new (cal) HRichCal; } cal->setMult(0); cal->setSector(fCalLoc[0]); cal->setRow(fCalLoc[1]); cal->setCol(fCalLoc[2]); cal->setTime(time); } else { Warning("addCalHit()", "Can't get slot sector=%i, row=%i, col=%i", fCalLoc[0], fCalLoc[1], fCalLoc[2]); return -1; } } // now increment the "charge" field by another hit: cal->addToT(tot); cal->increaseMult(); return 0; }