//*-- Created : 04/12/2009 by I.Koenig //_HADES_CLASS_DESCRIPTION /////////////////////////////////////////////////////////////////////////////// // // HStart2HitF // // This class implements the hit finder for the Start2 detector. // /////////////////////////////////////////////////////////////////////////////// #include "hades.h" #include "hcategory.h" #include "hevent.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hstart2cal.h" #include "hstart2detector.h" #include "hstart2hit.h" #include "hstart2hitf.h" #include "hstart2hitfpar.h" #include "hstartdef.h" #include "hitofraw.h" #include "hitofdetector.h" #include "hitofdef.h" #include #include #include using namespace std; ClassImp(HStart2HitF) HStart2HitF::HStart2HitF(void) : HReconstructor() { // default constructor fCatCal = NULL; fCatITofRaw = NULL; fCatHit = NULL; fPar = NULL; fpiTofCalPar = NULL; fSkipEvent = kFALSE; fUseInnerTOF = kFALSE; } HStart2HitF::HStart2HitF(const Text_t *name, const Text_t *title, Bool_t skip, Bool_t itof) : HReconstructor(name, title) { // constructor fCatCal = NULL; fCatITofRaw = NULL; fCatHit = NULL; fPar = NULL; fpiTofCalPar = NULL; fSkipEvent = skip; fUseInnerTOF = itof; } Bool_t HStart2HitF::init(void) { // gets the Start2Cal category and creates the Start2Hit category // creates an iterator which loops over all cells in Start2Cal // initialize parameter container HStart2Detector *det = static_cast(gHades->getSetup()->getDetector("Start")); if (NULL == det) { Error("init", "No Start Detector found."); return kFALSE; } fCatCal = gHades->getCurrentEvent()->getCategory(catStart2Cal); if (NULL == fCatCal) { Error("init", "HStart2Cal category not available!"); return kFALSE; } fCatHit = det->buildCategory(catStart2Hit); if (NULL == fCatHit) { Error("init", "HStart2Hit category not available!"); return kFALSE; } if (fUseInnerTOF) { HiTofDetector *itofdet = (HiTofDetector *)gHades->getSetup()->getDetector("iTof"); if (!itofdet) { Error("init()", "No iTof detector in setup!"); return kFALSE; } fCatITofRaw = gHades->getCurrentEvent()->getCategory(catiTofRaw); if (NULL == fCatITofRaw) { Error("init", "HiTofRaw category not available!"); return kFALSE; } } HRuntimeDb *rtdb = gHades->getRuntimeDb(); fPar = static_cast(rtdb->getContainer("Start2HitFPar")); if (NULL == fPar) { Error("init", "Pointer to Start2HitFPar parameters is NULL"); return kFALSE; } if (fUseInnerTOF) { fpiTofCalPar = (HiTofCalPar *)rtdb->getContainer("iTofCalPar"); } loc.set(1, 0); fActive = kTRUE; return kTRUE; } Int_t HStart2HitF::execute(void) { // makes the hits and fills the HStartHit category HStart2Cal *pCal = NULL; HiTofRaw *pITofRaw = NULL; HStart2Hit *pHit = NULL; Bool_t foundTime = kFALSE; Int_t module = -1; Int_t strip = -1; fSecondTime = -10000; Int_t newstrip = -1; Float_t firstTime = -10000; firstCluster.clear(); secondCluster.clear(); if (fUseInnerTOF) { // if one want to estimate T0 from InnerTOF measurement Float_t sumTime = 0; Float_t sumWidth = 0; Int_t nTime = 0; HLocation fLoc; fLoc.set(3, -1, -1, -1); for (Int_t entry = 0; entry < fCatITofRaw->getEntries(); entry++) { pITofRaw = (HiTofRaw *)fCatITofRaw->getObject(entry); if (!pITofRaw) continue; fLoc[0] = pITofRaw->getSector(); fLoc[1] = pITofRaw->getModule(); fLoc[2] = pITofRaw->getCell(); if (fLoc[0] == -1 && fLoc[1] == -1 && fLoc[2] == -1) continue; sumTime = 0; sumWidth = 0; nTime = 0; for (Int_t j = 0; j < 12; j++) // 12 SiMP channels used for Time, MeanTime and Eloss { if (pITofRaw->getTime(j) > -1000000) // unpacker gave us something for this channel { Float_t calTime = fpiTofCalPar->calibrateTime(fLoc[0], fLoc[1], fLoc[2], j, pITofRaw->getTime(j)); Float_t calELoss = fpiTofCalPar->calibrateCharge(fLoc[0], fLoc[1], fLoc[2], j, pITofRaw->getWidth(j)); sumTime += calTime; sumWidth += calELoss; nTime++; } } Float_t padMeanTime = sumTime / ((Float_t)nTime); Float_t padMeanWidth = sumWidth / ((Float_t)nTime); Int_t padIndex = fLoc[0]*3+fLoc[2]; // Check if such pad mean time is acceptable within the hitFinderParams if (padMeanTime > (fPar->getMeanTime(0, padIndex) - fPar->getWidth(0, padIndex)) && padMeanTime < (fPar->getMeanTime(0, padIndex) + fPar->getWidth(0, padIndex))) { // write data to the ouput category if (!foundTime) { pHit = static_cast(fCatHit->getNewSlot(loc)); // added "New", L.Chlad if (NULL != pHit) { pHit = new (pHit) HStart2Hit; } else { Error("execute", "Can't get slot mod=%i, chan=%i", loc[0], loc[1]); return -1; } } // First hit or earlier than the previous hit if (!foundTime || (firstTime > padMeanTime)) { pHit->setAddress(0, padIndex); pHit->setTimeAndWidth(padMeanTime, padMeanWidth); pHit->setFlag(kTRUE); pHit->setIteration(1); firstTime = pHit->getTime(); // JUST DUMMY CLUSTER INFO FROM INNER TOF!!! // newstrip = entry * 1000 + 1; pHit->setMultiplicity(1); pHit->setClusterStrip(0, 0); pHit->setSecondTime(fSecondTime); } foundTime = kTRUE; } } } else { // original Start2HitFinder for (Int_t entry = 0; entry < fCatCal->getEntries(); ++entry) { if (NULL == (pCal = static_cast(fCatCal->getObject(entry)))) { Error("execute", "Pointer to HStart2Cal object == NULL, returning"); return -1; } // check the times and apply a time cut to remove BKG // in strip 7 at least the reference time after calibration // should be in the data if (pCal->getModule() > 1) continue; // skip veto for (Int_t i = 0; i < pCal->getMultiplicity() && i < pCal->getMaxMultiplicity(); ++i) { if (pCal->getTime(i + 1) > (fPar->getMeanTime(pCal->getModule(), pCal->getStrip()) - fPar->getWidth(pCal->getModule(), pCal->getStrip())) && pCal->getTime(i + 1) < (fPar->getMeanTime(pCal->getModule(), pCal->getStrip()) + fPar->getWidth(pCal->getModule(), pCal->getStrip()))) { pCal->getAddress(module, strip); // write data to the ouput category if (!foundTime) { pHit = static_cast(fCatHit->getNewSlot(loc)); // added "New", L.Chlad if (NULL != pHit) { pHit = new (pHit) HStart2Hit; } else { Error("execute", "Can't get slot mod=%i, chan=%i", loc[0], loc[1]); return -1; } } // First hit or earlier than the previous hit if (!foundTime || firstTime > pCal->getTime(i + 1)) { pHit->setAddress(module, strip); pHit->setTimeAndWidth(pCal->getTime(i + 1), pCal->getWidth(i + 1)); pHit->setFlag(kTRUE); pHit->setMultiplicity(pCal->getMultiplicity()); firstTime = pHit->getTime(); newstrip = entry * 1000 + i + 1; } foundTime = kTRUE; } } } //---------------------------------------------------------------------- // cluster info's vector vtemp; Float_t maxdiff = 2; // ns with arround starttime used to cluster Float_t newStart2 = -100000; // clostest scond time Float_t timediff = 100000; // local var Int_t nextHit = -1; if (foundTime) firstCluster.push_back(newstrip); for (Int_t entry = 0; entry < fCatCal->getEntries(); ++entry) { if (NULL == (pCal = static_cast(fCatCal->getObject(entry)))) { Error("execute", "Pointer to HStart2Cal object == NULL, returning"); return -1; } if (pCal->getModule() > 1) continue; // reject veto // check the times and apply a time cut to remove BKG // in strip 7 at least the reference time after calibration // should be in the data for (Int_t i = 0; i < pCal->getMultiplicity() && i < pCal->getMaxMultiplicity(); ++i) { if (pCal->getTime(i + 1) > (fPar->getMeanTime(pCal->getModule(), pCal->getStrip()) - fPar->getWidth(pCal->getModule(), pCal->getStrip())) && pCal->getTime(i + 1) < (fPar->getMeanTime(pCal->getModule(), pCal->getStrip()) + fPar->getWidth(pCal->getModule(), pCal->getStrip()))) { Float_t time = pCal->getTime(i + 1); newstrip = entry * 1000 + i + 1; Float_t diff = TMath::Abs(firstTime - time); if (diff < maxdiff) { // first cluster if (find(firstCluster.begin(), firstCluster.end(), newstrip) == firstCluster.end()) { firstCluster.push_back(newstrip); } } else { // second cluster vtemp.push_back(newstrip); if (diff < timediff) { timediff = diff; nextHit = newstrip; newStart2 = time; } } // end second clust } // end window } // hitloop } // end strip loop if (vtemp.size() > 0) { // there was something else fSecondTime = newStart2; secondCluster.push_back(nextHit); for (UInt_t i = 0; i < vtemp.size(); i++) { if (find(secondCluster.begin(), secondCluster.end(), vtemp[i]) == secondCluster.end()) { secondCluster.push_back(vtemp[i]); } } } //-------------------------------------------------------------------- // fill cluster infos if (firstCluster.size() > 0) { pHit = static_cast(fCatHit->getObject(0)); if (NULL == pHit) { Error("execute()", "Pointer to HStart2Hit object == NULL"); } else { pHit->setIteration(1); pHit->resetClusterStrip(2); for (UInt_t i = 0; i < firstCluster.size(); i++) { pHit->setClusterStrip(0, firstCluster[i]); } for (UInt_t i = 0; i < secondCluster.size(); i++) { pHit->setClusterStrip(1, secondCluster[i]); } pHit->setSecondTime(fSecondTime); if (secondCluster.size() > 0) pHit->setMultiplicity(2); else pHit->setMultiplicity(1); } } } //---------------------------------------------------------------------- if (kFALSE == foundTime && kTRUE == fSkipEvent) { return kSkipEvent; } return 0; }