8 #include "St_DataSetIter.h"
16 #include <StMessMgr.h>
20 #include <StEEmcUtil/database/StEEmcDb.h>
21 #include <StEEmcUtil/database/EEmcDbItem.h>
22 #include <StEEmcUtil/database/EEmcDbCrate.h>
26 #include "StEmcUtil/geometry/StEmcGeom.h"
27 #include "StEmcUtil/database/StBemcTables.h"
28 #include "StEmcUtil/database/StEmcDecoder.h"
31 #include "StEventTypes.h"
32 #include "StEvent/StEvent.h"
33 #include "StEvent/StEmcCollection.h"
34 #include "StEvent/StEmcDetector.h"
35 #include "StEvent/StTriggerId.h"
36 #include "StEvent/StTriggerIdCollection.h"
39 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
40 #include "StMuDSTMaker/COMMON/StMuDst.h"
41 #include "StMuDSTMaker/COMMON/StMuTriggerIdCollection.h"
42 #include "StMuDSTMaker/COMMON/StMuEvent.h"
45 #include "L2algoUtil/L2EmcDb.h"
46 #include "L2algoUtil/L2EmcGeom.h"
47 #include "L2algoUtil/L2DbConfig.h"
48 #include "L2algoUtil/L2DbTime.h"
49 #include "L2algoUtil/L2btowCalAlgo09.h"
50 #include "L2algoUtil/L2etowCalAlgo09.h"
51 #include "L2pedAlgo/L2pedAlgo09.h"
54 #include "StMuDSTMaker/EZTREE/EztTrigBlob.h"
55 #include "St_db_Maker/St_db_Maker.h"
58 #include "StTriggerSimuMaker.h"
59 #include "StTriggerUtilities/Eemc/StEemcTriggerSimu.h"
60 #include "StTriggerUtilities/Eemc/EMCdsm2Tree.h"
62 #include "StGenericL2Emulator2009.h"
65 #define MaxBtowRdo (L2EmcDb::BTOW_MAXFEE*L2EmcDb::BTOW_DATSIZE)
66 #define MaxEtowRdo (L2EmcDb::ETOW_MAXFEE*L2EmcDb::ETOW_DATSIZE)
71 mBTOW_BANK =
new unsigned short [MaxBtowRdo];
72 mETOW_BANK =
new unsigned short [MaxEtowRdo];
86 StGenericL2Emulator2009::~StGenericL2Emulator2009(){
98 void StGenericL2Emulator2009::init(){
101 mDbE = (
StEEmcDb*)StMaker::GetChain()->GetDataSet(
"StEEmcDb");
103 mGeomB = StEmcGeom::instance(
"bemc");
108 LOG_INFO << Form(
"generic:init() , use: MuDst=1 (StEvent=0)=%d isMC=%d",mUseMuDst,mMCflag) <<endm;
115 StGenericL2Emulator2009::make(){
116 #if 0 // filter some events base on L0-trigger decision, if you want
122 LOG_INFO<<Form(
"sim L0,dsm2,EEMC: EJP2bit=%d; EEtot1bit=%d , val=%d",
123 dsm2tree->getOutEndcapJP2bit(), dsm2tree->getOutEndcapSum1bit(),dsm2tree->getIntEndcapSum())<<endm;
125 if(dsm2tree->getOutEndcapJP2bit()==0)
return;
138 doBanksFromStRawData();
141 const int fakeToken1 = 1;
142 const int fakeToken2 = 2;
146 l2btowCal09->calibrateBtow(fakeToken2,mBTOW_in,mBTOW_BANK);
147 l2etowCal09->calibrateEtow(fakeToken2,mETOW_in,mETOW_BANK);
149 l2ped->doPedestals(nInpTrg,(
int*)mL2Result,mBTOW_in,mBTOW_BANK,mETOW_in,mETOW_BANK);
150 for(
size_t ia=3;ia<mL2algo.size();ia++) {
151 if(mL2algo[ia]==0)
continue;
152 mL2algo[ia]->compute(fakeToken2);
153 mL2algo[ia]->decision(fakeToken2,mBTOW_in,mETOW_in,(
int*)mL2Result);
155 l2btowCal09->clear(fakeToken1);
156 l2etowCal09->clear(fakeToken1);
166 StGenericL2Emulator2009::initRun1(){
171 mYear=mydb->GetDateTime().GetYear();
172 mYearMonthDay=mydb->GetDateTime().GetDate();
173 mHourMinSec=mydb->GetDateTime().GetTime();
177 mSetPath=Form(
"%sL2/%d/db/",mSetupPath.Data(),mYear);
178 LOG_INFO <<
"initRun1() "<<
"DB setPath="<<mSetPath.Data()<<
" outPath="<<mOutPath.Data()<<endm;
182 L2DbTime * confL2 = confDB1.getConfiguration( mYearMonthDay, mHourMinSec );
187 if(mL2EmcDb)
delete mL2EmcDb;
188 mL2EmcDb=
new L2EmcDb((
char*)mSetPath.Data(),(
char*)mOutPath.Data());
190 mL2EmcDb->
setPedFile ( confL2->getPedFile() );
198 StMaker* maker= StMaker::GetChain()->GetMaker(
"StarDb");
201 mMappB =
new StEmcDecoder(mydb->GetDateTime().GetDate(),mydb->GetDateTime().GetTime());
202 LOG_INFO <<
"initRun1() done"<<endm;
210 StGenericL2Emulator2009::initRun2(
int runNo){
211 assert(mL2EmcDb->initRun(runNo) == 0);
216 float floatsPar[mxPar];
218 LOG_INFO << Form(
"initRun2() run#=%d begin",runNo)<<endm;
219 L2DbConfig confDB2(mSetPath+
"/L2TriggerIds.dat");
221 for(
size_t ia=0;ia<mL2algo.size();ia++) {
223 if (mL2algo[ia]==0)
continue;
224 TString algoName=mL2algo[ia]->getName();
225 L2DbTime *config = confDB2.getConfiguration(mYearMonthDay,mHourMinSec,algoName);
227 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;
228 mL2algo[ia]=0;
continue;
231 TString aa1 = config->getBuf1();
232 TString aa2 = config->getBuf2();
233 Int_t trgId = atoi(aa2.Data());
234 LOG_INFO<<Form(
"L2algo=%s=initRun2(), trigID=%d setup=%s= ",algoName.Data(),trgId,aa1.Data())<<endm;
236 TString fullPath=Form(
"%sL2/%d/algos/%s", mSetupPath.Data(), mYear,aa1.Data());
237 L2VirtualAlgo2009::readParams(fullPath, mxPar, intsPar, floatsPar);
238 mL2algo[ia]->initRun(runNo,intsPar,floatsPar);
239 mL2algo[ia]->setOflTrigID(trgId);
241 LOG_INFO <<
"initRun2() done"<<endm;
246 StTriggerSimuDecision
247 StGenericL2Emulator2009::isTrigger(
int trigId) {
248 if (mAcceptTriggerList.find(trigId) != mAcceptTriggerList.end())
return kYes;
249 if (mVetoTriggerList.find(trigId) != mVetoTriggerList.end())
return kNo;
256 StGenericL2Emulator2009::finish() {
258 LOG_INFO <<
"Finish()=======\n totEveSeen="<< mTotInpEve<<endm;
260 for(
size_t ia=0;ia<mL2algo.size();ia++)
261 if(mL2algo[ia]) mL2algo[ia]->finishRun();
262 LOG_INFO <<
"Finish()======= end"<<endm;
268 StGenericL2Emulator2009::clear( ){
270 memset(mBTOW_BANK,0,MaxBtowRdo*
sizeof(
unsigned short));
271 memset(mETOW_BANK,0,MaxEtowRdo*
sizeof(
unsigned short));
272 memset(mL2Result,0,
sizeof(mL2Result));
273 mAcceptTriggerList.clear();
274 mVetoTriggerList.clear();
282 StEvent* mEvent = (
StEvent*)StMaker::GetChain()-> GetInputDS(
"StEvent");
286 StEmcDetector* twB = emcCollection->detector(kBarrelEmcTowerId);
287 StEmcDetector* twE = emcCollection->detector(kEndcapEmcTowerId);
289 printf(
" StGenericL2Emulator2009 found no E-EMC tower data in StEvent, skip event\n");
296 printf(
" StGenericL2Emulator2009:: B_EMC Tower HITS ...\n");
297 for ( i = 1; i <= (int)twB->numberOfModules(); i++) {
298 StSPtrVecEmcRawHit& emcTowerHits = twB->module(i)->hits();
300 for ( j = 0; j < emcTowerHits.size(); j++) {
301 int adc= emcTowerHits[j]->adc();
302 int mod= emcTowerHits[j]->module();
303 int sub= emcTowerHits[j]->sub();
304 int eta= emcTowerHits[j]->eta();
305 float energy= emcTowerHits[j]->energy();
306 printf(
"j=%d, mod=%d, sub=%d, eta=%d adc=%d ener=%f\n",j,mod,sub,eta,adc,energy);
310 printf(
"StGenericL2Emulator2009 found no B-EMC tower data in StEvent, skip event\n");
314 printf(
"StGenericL2Emulator2009:: E_EMC Tower HITS ... %d\n",twE->numberOfModules());
315 for ( i = 0; i < (int)twE->numberOfModules(); i++) {
318 if(stmod==0)
continue;
319 StSPtrVecEmcRawHit& emcTowerHits = stmod->hits();
321 for ( j = 0; j < emcTowerHits.size(); j++) {
322 int adc= emcTowerHits[j]->adc();
323 int sec= emcTowerHits[j]->module()+1;
324 int sub= emcTowerHits[j]->sub()+
'A';
325 int eta= emcTowerHits[j]->eta()+1;
326 float energy= emcTowerHits[j]->energy();
327 printf(
"j=%d, sec=%d, sub=%c, eta=%d adc=%d ener=%f\n",j,sec,sub,eta,adc,energy);
331 printf(
"StGenericL2Emulator2009 found no E-EMC tower data in StEvent, skip event\n");
340 StGenericL2Emulator2009::doBanksFromStRawData(){
341 assert(mUseMuDst==
false);
345 StEvent *mEvent = (
StEvent *)StMaker::GetChain()-> GetInputDS(
"StEvent");
347 LOG_ERROR<<
"StGenericL2Emulator2009::getStEmcDetector() -- no StEvent found" << endm; return ;
357 StEmcRawData *rawB = mEvent->emcCollection()->bemcRawData();
360 printf(
" BTOW size=%d\n",rawB->sizeData(icr));
361 assert(rawB->sizeData(icr) <=MaxBtowRdo);
362 unsigned short* adc=rawB->data(icr);
365 for(i=0;i<rawB->sizeData(icr);i++) mBTOW_BANK[i]=adc[i];
368 StEmcRawData *rawE = mEvent->emcCollection()->eemcRawData();
370 assert(rawE->sizeData(icr) <=MaxEtowRdo);
372 for(icr=0;icr<mDbE->getNFiber();icr++) {
374 if(fiber->
crID>6)
continue;
375 if(rawE->sizeHeader(icr)<=0)
continue;
376 assert(fiber->
useIt);
377 printf(
" ETOW crID=%d type=%c size=%d\n",fiber->
crID,fiber->
type,rawE->sizeData(icr));
378 assert(fiber->
crID==icr+1);
379 unsigned short* adc=rawE->data(icr);
381 for(i=0;i<rawE->sizeData(icr);i++) {
382 int rdo=icr + i*L2EmcDb::ETOW_MAXFEE;
383 assert(rdo>=0 && rdo<MaxEtowRdo);
384 mETOW_BANK[rdo]=adc[i];
399 StGenericL2Emulator2009::doBanksFromMuDst(){
401 assert(mUseMuDst==
true);
403 StEvent *mEvent = (
StEvent*)StMaker::GetChain()-> GetInputDS(
"StEvent");
414 for (i=0; i < muEmc->getNEndcapTowerADC(); i++) {
415 int sec,eta,sub,rawAdc;
416 muEmc->getEndcapTowerADC(i,rawAdc,sec,sub,eta);
417 assert(sec>0 && sec<=MaxSectors);
419 const EEmcDbItem *x=mDbE->getTile(sec,
'A'+sub-1,eta,
'T');
423 int rdo=x->crate-1 + x->
chan*L2EmcDb::ETOW_MAXFEE;
424 mETOW_BANK[rdo]=rawAdc;
428 LOG_DEBUG << Form(
"doBanksFromMuDst() , ETOW nAdc=%d",nE)<<endm; assert(nE==720);
441 for(Int_t m = 1; m <= 120; ++m)
446 StSPtrVecEmcRawHit& rawHit=module->hits();
447 for(UInt_t k = 0; k < rawHit.size(); ++k)
453 Int_t m=rawHit[k]->module();
454 Int_t e=rawHit[k]->eta();
455 Int_t s=abs(rawHit[k]->sub());
456 Int_t adc=rawHit[k]->adc();
459 mGeomB->getId(m,e,s,did);
475 for (
id=1;
id <=4800 ;
id++)
477 int rawAdc= muEmc->getTowerADC(
id);
480 mBTOW_BANK[RDO]=rawAdc;
491 LOG_INFO << Form(
"doBanksFromMuDst() , BTOW nAdc=%d",nB)<<endm;
504 printf(
"printBEblocks(), just begin & end of each block, mBTOW_in=%d mETOW_in=%d\n",mBTOW_in,mETOW_in);
507 for(i=0;i<10;i++) printf(
"BTOWi=%d ADC=%d\n",i,mBTOW_BANK[i]);
508 for(i=4790;i<4800;i++) printf(
"BTOWi=%d ADC=%d\n",i,mBTOW_BANK[i]);
512 for(i=0;i<10;i++) printf(
"ETOWi=%d ADC=%d\n",i,mETOW_BANK[i]);
513 for(i=710;i<720;i++) printf(
"ETOWi=%d ADC=%d\n",i,mETOW_BANK[i]);
521 StGenericL2Emulator2009::addTriggerList() {
523 for(
size_t ia=0;ia<mL2algo.size();ia++) {
524 if (mL2algo[ia]==0)
continue;
525 if (mL2algo[ia]->getOflTrigID()==0)
continue;
526 if (mL2algo[ia]->isAccepted()) {
527 mAcceptTriggerList.insert(mL2algo[ia]->getOflTrigID());
530 mVetoTriggerList.insert(mL2algo[ia]->getOflTrigID());
534 LOG_DEBUG << Form(
"addTriggerList() yesSize=%d vetoSize=%d",mAcceptTriggerList.size(),mVetoTriggerList.size())<<endm;
void setPedFile(const char *c)
int useIt
flag to ignore data from misconfig/broken crate/box
void printBEtowers()
hits in StEvent
void setMaskFile(const char *c)
void loadTables(StMaker *anyMaker)
load tables.
void printBEblocks()
regenerated banks
char type
is 'T' for towers & 'S' for MAPMT
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
virtual Int_t GetIventNumber() const
Returns the current event number.
int GetDaqIdFromTowerId(int softId, int &RDO) const
Get Daq Id from Software Id for towers.