//*-- Author : Jochen Markert 12.03.2025 #include "hparticletriggeremu.h" #include "hades.h" #include "hruntimedb.h" #include "hevent.h" #include "hbeamtime.h" #include "hcategorymanager.h" #include "tofdef.h" #include "rpcdef.h" #include "hitofdef.h" #include #include using namespace std; //_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////////////////////// // // // HParticleTriggerEmu // // This class simulate the trigegr condition for simulations for the implemented // HADES beam times. // By default the class should be added to the task list of dst production after // TOF , RPC and iTOF tasksets, since their output is used in the trigger sim. // By default the class will set the TriggerBit in HEventHeader, but event which // do not fullfill the trigger condition will not be skipped. Both features can be // configured by : // void setSkipEvent(UInt_t trigBit,Bool_t skip = kTRUE) default : kFALSE // in trigBit the bits for the selected triggers have to set (example: bit 14 for pt3, // bit 13 for pt2). Incase not all triggers are fullfilled the event will be skipped. // // void setTriggerBitInEventHeader(Bool_t set = kTRUE) default : kTRUE // The bit set in EventHader can be checked by: // gHades->getCurrentEvent()->getHeader()->isTBit(14-1);(needs bitnr-1: pt3 -> 14-1) //////////////////////////////////////////////////////////////////////////////// ClassImp(HParticleTriggerEmu) HParticleTriggerEmu::HParticleTriggerEmu(const Text_t* name,const Text_t* title) : HReconstructor(name, title) { fTofRawSimCat = 0; fiTofCalSimCat = 0; fRpcCalSimCat = 0; fsetTriggerBit = kTRUE; fskipEvent = kFALSE ; fSelectionTrigger = 0; } HParticleTriggerEmu::~HParticleTriggerEmu(void) { } Bool_t HParticleTriggerEmu::init(void) { // get the category pointer to the HTofRawSim, HRpcCalSim, HiTofCalSim category cout<<"################################################################"<getBeamTimeID() == HADES::kFeb22){ // HBeamTime } else { Error("init()","No trigger emulation implemented for beam time : %s !",name.Data()); return kFALSE; } HCategory* geantKineCat = HCategoryManager::getCategory(catGeantKine,1, "HParticleTriggerEmu::init()"); if (!geantKineCat) { Error("HParticleTriggerEmu::init()","No HGeantKine cat in Input, you are running real data !"); return kFALSE; } if(gHades->getEmbeddingMode() > 0 ){ Error("HParticleTriggerEmu::init()","You are running embedding mode !"); return kFALSE; } fTofRawSimCat = HCategoryManager::getCategory(catTofRaw,1, "HParticleTriggerEmu::init()"); if (!fTofRawSimCat) { Error("HParticleTriggerEmu::init()","No HTofRaw Input !"); return kFALSE; } if(gHades->getBeamTimeID() == HADES::kFeb22){ // HBeamTime fiTofCalSimCat = HCategoryManager::getCategory(catiTofCal,1, "HParticleTriggerEmu::init()"); if (!fiTofCalSimCat) { Error("HParticleTriggerEmu::init()","No HiTofCal Input !"); return kFALSE; } } fRpcCalSimCat = HCategoryManager::getCategory(catRpcCal,1, "HParticleTriggerEmu::init()"); if (!fRpcCalSimCat) { Error("HParticleTriggerEmu::init()","No HRpcCal Input !"); return kFALSE; } return kTRUE; } Int_t HParticleTriggerEmu::execute(void) { UInt_t tBit = 0; if(gHades->getBeamTimeID() == HADES::kFeb22){ tBit = triggerFeb22(); } HEventHeader* header = gHades->getCurrentEvent()->getHeader(); if(fsetTriggerBit) header->setTBit(tBit); if(fskipEvent && !goodTrigger(tBit)) return kSkipEvent ; return 0; } UInt_t HParticleTriggerEmu::setTriggerBit(UInt_t& bits,UInt_t bit) { bits |= (0x01 << (bit-1)); return bits; } Bool_t HParticleTriggerEmu::goodTrigger(UInt_t tBit) { if(tBit == 0) return kFALSE; // no bit set if( (tBit&fSelectionTrigger) == fSelectionTrigger) return kTRUE; return kFALSE; } UInt_t HParticleTriggerEmu::triggerFeb22() { // return 0 if not trigger found // otherwise tbit 13 and 14 (pt2 pt3) // uses HTofRawSim, HiTofCalSim and HRpcCalSim UInt_t flag_trig = 0; HTofRawSim* cand_tof; HRpcCalSim* cand_rpc; HiTofCalSim* cand_itof; //**************************** Int_t tof_secMult[6] = {0}; Int_t rpc_secMult[6] = {0}; for(Int_t i = 0 ; i < fTofRawSimCat->getEntries(); i ++){ cand_tof = (HTofRawSim*) fTofRawSimCat->getObject(i); Int_t sec = cand_tof->getSector(); if(cand_tof->getLeftTime() > 0) tof_secMult[sec]++; if(cand_tof->getRightTime() > 0) tof_secMult[sec]++; } for(Int_t i = 0; i < 6; i ++){ if(tof_secMult[i] > 0) tof_secMult[i] /= 2; } for(Int_t i = 0 ; i < fRpcCalSimCat->getEntries(); i ++){ cand_rpc = (HRpcCalSim*) fRpcCalSimCat->getObject(i); Int_t sec = cand_rpc->getSector(); rpc_secMult[sec]++; } //******************* iTOF ********************************** Int_t iTof_sec [6] = {0}; Int_t iTof_sec_pad[6][3] = {0}; for(Int_t i = 0 ; i < fiTofCalSimCat->getEntries(); i ++){ cand_itof = (HiTofCalSim*) fiTofCalSimCat->getObject(i); Int_t sec = cand_itof->getSector(); Int_t ipad = cand_itof->getCell(); iTof_sec [sec]++; iTof_sec_pad[sec][ipad]++; } //************************************************** Int_t secMult_TofRpc = 0; for(Int_t i = 0; i < 6; i ++){ if( tof_secMult[i] || rpc_secMult[i]){ secMult_TofRpc++; } } //*************************************** Int_t fullSecMult = 0; for(Int_t i = 0; i < 6; i ++){ if((iTof_sec[i] && rpc_secMult[i]) || (iTof_sec[i] && tof_secMult[i])) fullSecMult++; } Int_t padMult = 0; for(Int_t j = 0; j < 6; j ++){ for(Int_t i = 0; i < 3; i ++){ if(iTof_sec_pad[j][i]) padMult++; } } //*********************** PT2/PT3 condition ************* //PT3 if( (padMult >= 3 && fullSecMult >= 2) || fullSecMult >= 3){ flag_trig = setTriggerBit(flag_trig,14); } if(fullSecMult >= 1){ flag_trig = setTriggerBit(flag_trig,13); } //************************************************ return flag_trig; }