//_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////// // // HRich700Trb3Unpacker // // Class for unpacking TRB3 data and filling // the Start2 Raw category // // Basic subevent decoding and eventual TDC corrections are // performed by decode function in the base class // see: /base/datasource/htrb3unpacker.h // ///////////////////////////////////////////////////////////// #include "hades.h" #include "hcategory.h" #include "hdebug.h" #include "hevent.h" #include "heventheader.h" #include "hldsource.h" #include "hldsubevt.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hrichdetector.h" #include "hrich700raw.h" #include "hrich700trb3lookup.h" //#include "hrich700trb3calpar.h" #include "hrich700trb3unpacker.h" #include "htrbnetunpacker.h" #include "richdef.h" #include using namespace std; ClassImp(HRich700Trb3Unpacker) // time over threshold cut, later as anaylsis parameter? #define RICH700_MAX_TOT 100 HRich700Trb3Unpacker::HRich700Trb3Unpacker(UInt_t id) : HTrb3Unpacker(id) { // constructor pRawCat = NULL; timeRef = kTRUE; lookup = NULL; } Bool_t HRich700Trb3Unpacker::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; } pRawCat = det->buildCategory(catRich700Raw); if (!pRawCat) return kFALSE; loc.set(2, 0, 0); lookup = (HRich700Trb3Lookup*)(gHades->getRuntimeDb()->getContainer("Rich700Trb3Lookup")); if (!lookup) { Error("init", "No Pointer to parameter container Rich700Trb3Lookup."); return kFALSE; } // calpar = (HRich700Trb3Calpar*)(gHades->getRuntimeDb()->getContainer("Start2Trb3Calpar")); // if (!calpar) { // Error("init", "No Pointer to parameter container Start2Trb3Calpar."); // return kFALSE; // } if (NULL == trbNetUnpacker) { if (gHades->getDataSource()) { HDataSource* source = gHades->getDataSource(); if (source->InheritsFrom("HldSource")) { trbNetUnpacker = ((HldSource *)gHades->getDataSource())->getTrbNetUnpacker(); } else { Warning("init", "DataSource not inherited from HldSource! trbNetUnpacker == 0 "); } } else { Warning("init", "Could not retrieve DataSource! trbNetUnpacker == 0 "); } } if (!trbNetUnpacker->init()) { Error("init", "Failed to initialize HTrbNetUnpacker!"); return kFALSE; } return kTRUE; } Int_t HRich700Trb3Unpacker::execute(void) { HRich700Raw *pRaw = 0; // pointer to Raw category if (gHades->isCalibration()) { //calibration event return 1; } if (gHades->getCurrentEvent()->getHeader()->getId() == 0xe) { //scaler event return 1; } // if there is no data, do not try to analyze it // pSubEvt - make sure that there is something for decoding if (!pSubEvt) return 1; Int_t nEvt = gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(); // decodes the subevent and fill arrays, see: htrb3unpacker.h if (!decode()) { Error("decode", "subsubevent decoding failed!!! Evt Nr : %i SubEvtId: %x", nEvt, subEvtId); return -1; } // correct for reference time here! if (timeRef) { for (unsigned n=0;ncorrectRefTimeCh(0)) { Error("decode", "time-correction for tdc %04x failed!!! Evt Nr : %i SubEvtId: %x", (unsigned) getTDC(n)->getTrbAddr(), nEvt, subEvtId); return -1; } } } for (unsigned ntdc=0;ntdcgetTdc(tdc->getTrbAddr()); if (!board) { if (debugFlag > 0) Warning("execute", "Evt Nr : %i SubEvId: %x (%i) unpacked but TDC Board 0x%x not in lookup table", nEvt, getSubEvtId(), getSubEvtId(), tdc->getTrbAddr()); continue; } // fill the raw category for RICH700 detector for (UInt_t i = 1; i < tdc->numChannels()-1; i++) { // first check that tdc channel exists in lookup table at all HRich700Trb3LookupChan *chan = board->getChannel(i); if (chan==0) continue; // than check that address in lookup-table is not empty chan->getAddress(loc[0], loc[1]); // pixel_row, pixel_col if (loc[0] < 0) continue; // from here we got access to TDC channel and should map it to RICH700 pixel pRaw = (HRich700Raw*)pRawCat->getObject(loc); if (!pRaw) { pRaw = (HRich700Raw *)pRawCat->getSlot(loc); if (pRaw) { pRaw = new(pRaw) HRich700Raw; pRaw->setAddress(loc[0], loc[1]); } else { Error("execute()", "Can't get slot pixel_row=%i, pixel_column=%i", loc[0], loc[1]); return -1; } } else { Error("execute", "Slot already exists for pixel_row=%i, pixel_column=%i", loc[0], loc[1]); return -1; } // JAM preliminary unpacker ---------- // todo: dynamically find out corresponding leading/trailing edges in map? // todo: handling of single leading/trailing edges? HTrb3TdcUnpacker::ChannelRec& theRecord = tdc->getCh(i); UInt_t lix=0; for(lix=0; lix0) { Double_t tot=tm1-tm0; if(totaddHit(tm0,tm1,tot,0b11); } else { pRaw->addHit(tm0,-1,-1,0b10); pRaw->addHit(-1,tm1,-1,0b01); } } else { // no corresponding trailing edge found pRaw->addHit(tm0,-1,-1,0b10); } } // now check for single trailing edges? for (UInt_t tix=lix; tix< theRecord.falling_mult; ++tix) { Double_t tm1=theRecord.falling_tm[tix]*1e9; pRaw->addHit(-1,tm1,-1,0b01); } /////////// old from start2 where leading and trailing edges are on different tdc channels // HTrb3TdcUnpacker::ChannelRec& rec0 = tdc->getCh(i); // // ignore channels without rising hits // if (rec0.rising_mult < 1) continue; // // HTrb3TdcUnpacker::ChannelRec& rec1 = tdc->getCh(i+1); // // // from here we got access to TDC channel and should map it to RICH700 pixel // pRaw = (HRich700Raw*)pRawCat->getObject(loc); // if (!pRaw) { // pRaw = (HRich700Raw *)pRawCat->getSlot(loc); // if (pRaw) { // pRaw = new(pRaw) HRich700Raw; // pRaw->setAddress(loc[0], loc[1]); // } else { // Error("execute()", "Can't get slot pmt=%i, pixel=%i", loc[0], loc[1]); // return -1; // } // } else { // Error("execute", "Slot already exists for pmt=%i, pixel=%i", loc[0], loc[1]); // return -1; // } // // fill ... // for (UInt_t chmult = 0; chmult < rec0.rising_mult; chmult++) { // // Double_t tm0 = rec0.rising_tm[chmult]*1e9; // // if (debugFlag > 0) // printf("--filling data TDC:%04x ch:%2d pmt:%2d pixel:%2d xtime: %6.3f\n", // tdc->getTrbAddr(), i, loc[0], loc[1], tm0); // // Double_t adc = -1000; // // for (UInt_t n1=0; n1tm1-tm0)) adc = tm1-tm0; // } // // pRaw->setTimeAndWidth(tm0, adc); // } } // loop over TDC channels } // loop over TDC return 1; }