6 #include "St_DataSetIter.h"
14 #include <StMessMgr.h>
18 #include <StEEmcUtil/database/StEEmcDb.h>
19 #include <StEEmcUtil/database/EEmcDbItem.h>
20 #include <StEEmcUtil/database/EEmcDbCrate.h>
24 #include "StEmcUtil/geometry/StEmcGeom.h"
25 #include "StEmcUtil/database/StBemcTables.h"
26 #include "StEmcUtil/database/StEmcDecoder.h"
29 #include "StEventTypes.h"
30 #include "StEvent/StEvent.h"
31 #include "StEvent/StEmcCollection.h"
32 #include "StEvent/StEmcDetector.h"
33 #include "StEvent/StTriggerId.h"
34 #include "StEvent/StTriggerIdCollection.h"
37 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
38 #include "StMuDSTMaker/COMMON/StMuDst.h"
39 #include "StMuDSTMaker/COMMON/StMuTriggerIdCollection.h"
40 #include "StMuDSTMaker/COMMON/StMuEvent.h"
43 #include "StDaqLib/TRG/trgStructures.h"
46 #include "L2algoUtil/L2EmcDb.h"
47 #include "L2algoUtil/L2DbConfig.h"
48 #include "L2algoUtil/L2DbTime.h"
51 #include "StMuDSTMaker/EZTREE/EztTrigBlob.h"
52 #include "St_db_Maker/St_db_Maker.h"
55 #include "StTriggerSimuMaker.h"
56 #include "StTriggerUtilities/Eemc/StEemcTriggerSimu.h"
57 #include "StTriggerUtilities/Eemc/EMCdsm2Tree.h"
59 #include "StGenericL2Emulator.h"
62 #define MaxBtowRdo (L2EmcDb::BTOW_MAXFEE*L2EmcDb::BTOW_DATSIZE)
63 #define MaxEtowRdo (L2EmcDb::ETOW_MAXFEE*L2EmcDb::ETOW_DATSIZE)
68 mBTOW_BANK =
new unsigned short [MaxBtowRdo];
69 mETOW_BANK =
new unsigned short [MaxEtowRdo];
84 StGenericL2Emulator::~StGenericL2Emulator(){
96 void StGenericL2Emulator::init(){
99 mDbE = (
StEEmcDb*)StMaker::GetChain()->GetDataSet(
"StEEmcDb");
101 mGeomB = StEmcGeom::instance(
"bemc");
105 LOG_INFO << Form(
"generic:init() , use: MuDst=1 (StEvent=0)=%d isMC=%d",mUseMuDst,mMCflag) <<endm;
112 StGenericL2Emulator::make(){
114 #if 0 // filter some events base on L0-trigger decision, if you want
119 LOG_INFO<<Form(
"sim L0,dsm2,EEMC: EJP2bit=%d; EEtot1bit=%d , val=%d",
120 dsm2tree->getOutEndcapJP2bit(), dsm2tree->getOutEndcapSum1bit(),dsm2tree->getIntEndcapSum())<<endm;
122 if(dsm2tree->getOutEndcapJP2bit()==0)
return;
135 doBanksFromStRawData();
140 for(ia=0;ia<mL2algoN;ia++) {
141 if(mL2algo[ia]==0)
continue;
142 mL2algo[ia]-> doEvent(L0trgSwitch, mTotInpEve, (
TrgDataType*)mTrigData,mBTOW_in, mBTOW_BANK, mETOW_in, mETOW_BANK);
156 StGenericL2Emulator::initRun1(){
161 mYear=mydb->GetDateTime().GetYear();
162 mYearMonthDay=mydb->GetDateTime().GetDate();
163 mHourMinSec=mydb->GetDateTime().GetTime();
167 mSetPath=Form(
"%sL2/%d/db/",mSetupPath.Data(),mYear);
168 LOG_INFO <<
"initRun1() "<<
"DB setPath="<<mSetPath.Data()<<
" outPath="<<mOutPath.Data()<<endm;
172 L2DbTime * confL2 = confDB1.getConfiguration( mYearMonthDay, mHourMinSec );
177 if(mL2EmcDb)
delete mL2EmcDb;
178 mL2EmcDb=
new L2EmcDb((
char*)mSetPath.Data(),(
char*)mOutPath.Data());
180 mL2EmcDb->
setPedFile ( confL2->getPedFile() );
186 StMaker* maker= StMaker::GetChain()->GetMaker(
"StarDb");
189 mMappB =
new StEmcDecoder(mydb->GetDateTime().GetDate(),mydb->GetDateTime().GetTime());
190 LOG_INFO <<
"initRun1() done"<<endm;
198 StGenericL2Emulator::initRun2(
int runNo){
203 float floatsPar[mxPar];
205 LOG_INFO << Form(
"initRun2() run#=%d begin",runNo)<<endm;
206 L2DbConfig confDB2(mSetPath+
"/L2TriggerIds.dat");
209 for(ia=0;ia<mL2algoN;ia++) {
211 if (mL2algo[ia]==0)
continue;
212 TString algoName=mL2algo[ia]->getName();
213 L2DbTime *config = confDB2.getConfiguration(mYearMonthDay,mHourMinSec,algoName);
215 LOG_ERROR << Form(
"\n************\ninitRun2() failed L2-%s configuration for yyyy=%d hhmmss=%d,\n On explicit request from Renee, the L2 emulator will continue with disabled this particulra L2-algo.\nThis will result with false positives - ignore emulated trigger results for this algo,\nIt would be much better to fix the setup and provide missing record.\nYou have been warned, Jan B.\n***********\n",algoName.Data(),mYearMonthDay,mHourMinSec)<<endm;
216 mL2algo[ia]=0;
continue;
219 TString aa1 = config->getBuf1();
220 TString aa2 = config->getBuf2();
221 Int_t trgId = atoi(aa2.Data());
222 LOG_INFO<<Form(
"L2algo=%s=initRun2(), trigID=%d setup=%s= ",algoName.Data(),trgId,aa1.Data())<<endm;
224 TString fullPath=Form(
"%sL2/%d/algos/%s", mSetupPath.Data(), mYear,aa1.Data());
225 L2VirtualAlgo::readParams(fullPath, mxPar, intsPar, floatsPar);
226 assert(mL2algo[ia]->initRun( runNo,intsPar,floatsPar)==0);
227 mL2algo[ia]->setOflTrigID(trgId);
229 LOG_INFO <<
"initRun2() done"<<endm;
234 StTriggerSimuDecision
235 StGenericL2Emulator::isTrigger(
int trigId) {
237 for(j=0; j<mAcceptTriggerList.size();j++) {
238 if(trigId==mAcceptTriggerList[j])
return kYes;
240 for(j=0; j<mVetoTriggerList.size();j++) {
241 if(trigId==mVetoTriggerList[j])
return kNo;
249 StGenericL2Emulator::finish() {
251 LOG_INFO <<
"Finish()=======\n totEveSeen="<< mTotInpEve<<endm;
254 for(ia=0;ia<mL2algoN;ia++)
255 if(mL2algo[ia]) mL2algo[ia]->finishRun();
256 LOG_INFO <<
"Finish()======= end"<<endm;
262 StGenericL2Emulator::clear( ){
264 memset(mBTOW_BANK,0,MaxBtowRdo*
sizeof(
unsigned short));
265 memset(mETOW_BANK,0,MaxEtowRdo*
sizeof(
unsigned short));
267 mAcceptTriggerList.clear();
268 mVetoTriggerList.clear();
276 StEvent* mEvent = (
StEvent*)StMaker::GetChain()-> GetInputDS(
"StEvent");
280 StEmcDetector* twB = emcCollection->detector(kBarrelEmcTowerId);
281 StEmcDetector* twE = emcCollection->detector(kEndcapEmcTowerId);
283 printf(
" StGenericL2Emulator found no E-EMC tower data in StEvent, skip event\n");
290 printf(
" StGenericL2Emulator:: B_EMC Tower HITS ...\n");
291 for ( i = 1; i <= (int)twB->numberOfModules(); i++) {
292 StSPtrVecEmcRawHit& emcTowerHits = twB->module(i)->hits();
294 for ( j = 0; j < emcTowerHits.size(); j++) {
295 int adc= emcTowerHits[j]->adc();
296 int mod= emcTowerHits[j]->module();
297 int sub= emcTowerHits[j]->sub();
298 int eta= emcTowerHits[j]->eta();
299 float energy= emcTowerHits[j]->energy();
300 printf(
"j=%d, mod=%d, sub=%d, eta=%d adc=%d ener=%f\n",j,mod,sub,eta,adc,energy);
304 printf(
"StGenericL2Emulator found no B-EMC tower data in StEvent, skip event\n");
308 printf(
"StGenericL2Emulator:: E_EMC Tower HITS ... %d\n",twE->numberOfModules());
309 for ( i = 0; i < (int)twE->numberOfModules(); i++) {
312 if(stmod==0)
continue;
313 StSPtrVecEmcRawHit& emcTowerHits = stmod->hits();
315 for ( j = 0; j < emcTowerHits.size(); j++) {
316 int adc= emcTowerHits[j]->adc();
317 int sec= emcTowerHits[j]->module()+1;
318 int sub= emcTowerHits[j]->sub()+
'A';
319 int eta= emcTowerHits[j]->eta()+1;
320 float energy= emcTowerHits[j]->energy();
321 printf(
"j=%d, sec=%d, sub=%c, eta=%d adc=%d ener=%f\n",j,sec,sub,eta,adc,energy);
325 printf(
"StGenericL2Emulator found no E-EMC tower data in StEvent, skip event\n");
334 StGenericL2Emulator::doBanksFromStRawData(){
335 assert(mUseMuDst==
false);
339 StEvent *mEvent = (
StEvent *)StMaker::GetChain()-> GetInputDS(
"StEvent");
341 LOG_ERROR<<
"StGenericL2Emulator::getStEmcDetector() -- no StEvent found" << endm; return ;
351 StEmcRawData *rawB = mEvent->emcCollection()->bemcRawData();
354 printf(
" BTOW size=%d\n",rawB->sizeData(icr));
355 assert(rawB->sizeData(icr) <=MaxBtowRdo);
356 unsigned short* adc=rawB->data(icr);
359 for(i=0;i<rawB->sizeData(icr);i++) mBTOW_BANK[i]=adc[i];
362 StEmcRawData *rawE = mEvent->emcCollection()->eemcRawData();
364 assert(rawE->sizeData(icr) <=MaxEtowRdo);
366 for(icr=0;icr<mDbE->getNFiber();icr++) {
368 if(fiber->
crID>6)
continue;
369 if(rawE->sizeHeader(icr)<=0)
continue;
370 assert(fiber->
useIt);
371 printf(
" ETOW crID=%d type=%c size=%d\n",fiber->
crID,fiber->
type,rawE->sizeData(icr));
372 assert(fiber->
crID==icr+1);
373 unsigned short* adc=rawE->data(icr);
375 for(i=0;i<rawE->sizeData(icr);i++) {
376 int rdo=icr + i*L2EmcDb::ETOW_MAXFEE;
377 assert(rdo>=0 && rdo<MaxEtowRdo);
378 mETOW_BANK[rdo]=adc[i];
393 StGenericL2Emulator::doBanksFromMuDst(){
395 assert(mUseMuDst==
true);
397 StEvent *mEvent = (
StEvent*)StMaker::GetChain()-> GetInputDS(
"StEvent");
408 for (i=0; i < muEmc->getNEndcapTowerADC(); i++) {
409 int sec,eta,sub,rawAdc;
410 muEmc->getEndcapTowerADC(i,rawAdc,sec,sub,eta);
411 assert(sec>0 && sec<=MaxSectors);
413 const EEmcDbItem *x=mDbE->getTile(sec,
'A'+sub-1,eta,
'T');
417 int rdo=x->crate-1 + x->
chan*L2EmcDb::ETOW_MAXFEE;
418 mETOW_BANK[rdo]=rawAdc;
422 LOG_DEBUG << Form(
"doBanksFromMuDst() , ETOW nAdc=%d",nE)<<endm; assert(nE==720);
435 for(Int_t m = 1; m <= 120; ++m)
440 StSPtrVecEmcRawHit& rawHit=module->hits();
441 for(UInt_t k = 0; k < rawHit.size(); ++k)
447 Int_t m=rawHit[k]->module();
448 Int_t e=rawHit[k]->eta();
449 Int_t s=abs(rawHit[k]->sub());
450 Int_t adc=rawHit[k]->adc();
453 mGeomB->getId(m,e,s,did);
469 for (
id=1;
id <=4800 ;
id++)
471 int rawAdc= muEmc->getTowerADC(
id);
474 mBTOW_BANK[RDO]=rawAdc;
485 LOG_INFO << Form(
"doBanksFromMuDst() , BTOW nAdc=%d",nB)<<endm;
498 printf(
"printBEblocks(), just begin & end of each block, mBTOW_in=%d mETOW_in=%d\n",mBTOW_in,mETOW_in);
501 for(i=0;i<10;i++) printf(
"BTOWi=%d ADC=%d\n",i,mBTOW_BANK[i]);
502 for(i=4790;i<4800;i++) printf(
"BTOWi=%d ADC=%d\n",i,mBTOW_BANK[i]);
506 for(i=0;i<10;i++) printf(
"ETOWi=%d ADC=%d\n",i,mETOW_BANK[i]);
507 for(i=710;i<720;i++) printf(
"ETOWi=%d ADC=%d\n",i,mETOW_BANK[i]);
515 StGenericL2Emulator::addTriggerList() {
518 for(ia=0;ia<mL2algoN;ia++) {
519 if (mL2algo[ia]==0)
continue;
520 if (mL2algo[ia]->getOflTrigID()==0)
continue;
521 if (mL2algo[ia]->accepted())
522 mAcceptTriggerList.push_back(mL2algo[ia]->getOflTrigID());
524 mVetoTriggerList.push_back(mL2algo[ia]->getOflTrigID());
527 LOG_DEBUG << Form(
"addTriggerList() yesSize=%d vetoSize=%d",mAcceptTriggerList.size(),mVetoTriggerList.size())<<endm;
531 return ( (
TrgDataType*)mTrigData)->TrgSum.L2Result;
void setPedFile(const char *c)
int useIt
flag to ignore data from misconfig/broken crate/box
const unsigned int * result() const
bag of 64 bytes whose interpretation changes year-by-year
void setMaskFile(const char *c)
void loadTables(StMaker *anyMaker)
load tables.
char type
is 'T' for towers & 'S' for MAPMT
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
void printBEblocks()
regenerated banks
void printBEtowers()
hits in StEvent
int GetDaqIdFromTowerId(int softId, int &RDO) const
Get Daq Id from Software Id for towers.