//*-- Author : Rafal Lalik //*-- Created : 03.05.2017 //_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////// // HFRpcDigitizer // // This class digitizes the Forward Rpc detector data // // Produce calibrated Time and energy loss and the rpc number // ///////////////////////////////////////////////////////////// #include "hfrpcdigitizer.h" #include "hades.h" #include "hcategory.h" #include "hdebug.h" #include "hevent.h" #include "hfrpccalsim.h" #include "hfrpcdetector.h" #include "hfrpcdigipar.h" #include "hfrpcgeompar.h" #include "hgeantfrpc.h" #include "hgeantkine.h" #include "hgeomcompositevolume.h" #include "hgeomvector.h" #include "hgeomvolume.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hstart2hit.h" #include "hstartdef.h" #include // #define VERBOSE_MODE 1 using namespace std; ClassImp(HFRpcDigitizer); HFRpcDigitizer::HFRpcDigitizer() { // default constructor initVariables(); } HFRpcDigitizer::HFRpcDigitizer(const Text_t* name, const Text_t* title) : HReconstructor(name, title) { // constructor initVariables(); } void HFRpcDigitizer::initVariables() { // initialize the variables in constructor pGeantFRpcCat = nullptr; pCalCat = nullptr; pDigiPar = nullptr; pGeomPar = nullptr; fLoc.setNIndex(2); fLoc.set(2, 0, 0); } Bool_t HFRpcDigitizer::init() { // initializes the task // find the Forward detector in the HADES setup HFRpcDetector* pFRpc = (HFRpcDetector*)(gHades->getSetup()->getDetector("FRpc")); if (!pFRpc) { Error("FRpcDigitizer::init", "No Forward Detector found"); return kFALSE; } // GEANT input data pGeantFRpcCat = gHades->getCurrentEvent()->getCategory(catFRpcGeantRaw); if (!pGeantFRpcCat) { Error("HFRpcDigitizer::init()", "HGeant FRpc input missing"); return kFALSE; } // build the Calibration category pCalCat = pFRpc->buildCategory(catFRpcCal, kTRUE); if (!pCalCat) { Error("HFRpcDigitizer::init()", "Cal category not created"); return kFALSE; } // retrieve the parameter container pDigiPar = (HFRpcDigiPar*)gHades->getRuntimeDb()->getContainer("FRpcDigiPar"); if (!pDigiPar) { Error("HFRpcDigitizer::init()", "Parameter container for digitizer not created"); return kFALSE; } pGeomPar = (HFRpcGeomPar*)gHades->getRuntimeDb()->getContainer("FRpcGeomPar"); if (!pGeomPar) { Error("HFRpcDigitizer::init()", "Parameter container for geometry not created"); return kFALSE; } pStartHitCat = gHades->getCurrentEvent()->getCategory(catStart2Hit); if (!pStartHitCat) Warning("init", "Start hit level not defined; setting start time to 0"); for (Int_t s = 0; s < FRPC_MAX_SECTORS; ++s) for (Int_t c = 0; c < FRPC_MAX_STRIPS; ++c) frpcCellsLab[s][c] = nullptr; return kTRUE; } Bool_t HFRpcDigitizer::reinit() { for (Int_t s = 0; s < FRPC_MAX_SECTORS; ++s) { HModGeomPar* fmodgeom = pGeomPar->getModule(s); // If module/sector is disabled in geometry, skip it. if (!fmodgeom) continue; HGeomTransform labTrans = fmodgeom->getLabTransform(); cosa[s] = labTrans.getRotMatrix().getElement(0, 0); sina[s] = labTrans.getRotMatrix().getElement(1, 0); HGeomCompositeVolume* fMod = fmodgeom->getRefVolume(); for (Int_t c = 0; c < FRPC_MAX_STRIPS; ++c) { HGeomVolume* fVol = fMod->getComponent(c); if (frpcCellsLab[s][c] == nullptr) frpcCellsLab[s][c] = new HGeomVector; HGeomVector* p = frpcCellsLab[s][c]; *p = fVol->getTransform().getTransVector(); *p = labTrans.transFrom(*p); } } #ifdef VERBOSE_MODE pFRpcGeomPar->print(); #endif return kTRUE; } Int_t HFRpcDigitizer::execute() { //-------------------------------------------------- // start time extraction. // Getting start time smearing Float_t startTimeSmearing = 0; //[ns] if (pStartHitCat && pStartHitCat->getEntries() > 0) { HStart2Hit* pStartH = (HStart2Hit*)pStartHitCat->getObject(0); if (pStartH != NULL && pStartH->getResolution() != -1000) { startTimeSmearing = pStartH->getResolution(); } } // Digitization of GEANT hits and storage in HFRpcCalSim HGeantFRpc* ghit = 0; Char_t geaModule; // module number (0) Char_t geaSector; // sector number (0..3) Int_t geaCell; // cell/strip number Char_t geaSubCell; // sub cell number Int_t entries = pGeantFRpcCat->getEntries(); #ifdef VERBOSE_MODE printf("<<-- RPC: VERBOSE_MODE ON - process %3d entries ->>\n", entries); #endif for (Int_t i = 0; i < entries; ++i) { ghit = (HGeantFRpc*)pGeantFRpcCat->getObject(i); if (ghit) { ghit->getAddress(geaModule, geaSector, geaCell, geaSubCell); Int_t s = (Int_t)geaSector; // If sector is disabled in setup, skip it. if (!frpcCellsLab[s][0]) continue; Int_t strip = geaCell; GeantFields gf; ghit->getHit(gf.xHit, gf.yHit, gf.zHit, gf.pxHit, gf.pyHit, gf.pzHit, gf.tofHit, gf.trackLength, gf.eHit); gf.trackNumber = ghit->getTrackNumber(); Float_t x_lab = frpcCellsLab[s][strip]->X() + (gf.xHit * cosa[s] - gf.yHit * sina[s]); Float_t y_lab = frpcCellsLab[s][strip]->Y() + (gf.xHit * sina[s] + gf.yHit * cosa[s]); Float_t strip_half_len = 750. / 2; // FIXME Float_t base_time = gf.tofHit + pDigiPar->getTimeOffset(); // estimation of time Float_t tN = (strip_half_len - gf.yHit) / pDigiPar->getTimeProp() + base_time; Float_t tF = (strip_half_len + gf.yHit) / pDigiPar->getTimeProp() + base_time; // FRpc intrinsic smearing tN = gRandom->Gaus(tN, pDigiPar->getTimeReso()) - startTimeSmearing; tF = gRandom->Gaus(tF, pDigiPar->getTimeReso()) - startTimeSmearing; // fake charge Float_t ql = 10; // (strip_half_len + gf.yHit) / time_prop + pDigiPar->getTimeOffset(); Float_t qr = 10; //(strip_half_len - gf.yHit) / time_prop + pDigiPar->getTimeOffset(); #ifdef VERBOSE_MODE printf("[%2d] (%d,%d,%d,%d) -> (%d,%d,%d,%d)\n", gf.trackNumber, geaModule, geaLayer, geaCell, geaSubCell, sector, layer, geaCell, geaSubCell); printf("(%d,%d) cosa=%f, sina=%f, off=%f ", m, l, cosa[m], sina[m], offset[m][l]); printf("gea: %f,%f -> %f,%f -> lab: %f,%f\n", gf.xHit, gf.yHit, xx, yy, cf.x, cf.y); #endif fLoc[0] = s; // sector fLoc[1] = strip; // strip HFRpcCalSim* cal = (HFRpcCalSim*)pCalCat->getObject(fLoc); if (cal == nullptr) { cal = (HFRpcCalSim*)pCalCat->getSlot(fLoc); cal = new (cal) HFRpcCalSim; cal->setAddress(s, strip); } if (cal) { cal->reconstructHits(tN, tF, ql, qr, frpcCellsLab[s][strip]->Z(), pDigiPar->getTimeProp(), pDigiPar->getStripLength(), 0, 0, frpcCellsLab[s][strip], cosa[s], sina[s], 0.f, 0.f, 0.f); cal->setGeaHit(x_lab, y_lab, gf.tofHit); #ifdef VERBOSE_MODE cal->print(); printf("\n"); #endif } else { // Error handling here } } } return 0; }