11 #include <StMessMgr.h>
13 #include "StEemcTriggerSimu.h"
14 #include "EemcHttpInfo.h"
16 #include "StEvent/StEvent.h"
17 #include "StEvent/StEventTypes.h"
18 #include "StEvent/StEmcTriggerDetector.h"
19 #include "StEvent/StL0Trigger.h"
23 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
24 #include "StMuDSTMaker/COMMON/StMuDst.h"
25 #include "StMuDSTMaker/COMMON/StMuEvent.h"
26 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
28 #include "St_db_Maker/St_db_Maker.h"
31 #include <StEEmcUtil/database/StEEmcDb.h>
32 #include <StEEmcUtil/database/EEmcDbCrate.h>
33 #include <StEEmcUtil/database/EEmcDbItem.h>
34 #include <StEEmcUtil/database/cstructs/eemcConstDB.hh>
37 #include "EEfeeTPTree.h"
39 #include "EEdsm0Tree.h"
40 #include "EEdsm1Tree.h"
41 #include "EMCdsm2Tree.h"
43 #include "EemcTrigUtil.h"
47 #include "StTriggerUtilities/StDSMUtilities/StDSM2009Utilities.hh"
56 StEemcTriggerSimu::StEemcTriggerSimu() {
78 LOG_INFO <<
"Eemc::constructor"<<endm;
84 StEemcTriggerSimu::~StEemcTriggerSimu()
86 delete mE001; mE001 = 0;
87 delete mE101; mE101 = 0;
93 StEemcTriggerSimu::Clear(){
96 memset(rawAdc,0,
sizeof(rawAdc));
97 feeTPTreeADC->clear();
100 dsm2TreeADC->clear();
103 dsm0TreeTRG->clear();
104 dsm1TreeTRG->clear();
105 dsm2TreeTRG->clear();
115 StEemcTriggerSimu::Init(){
119 mDbE = (
StEEmcDb*)StMaker::GetChain()->GetDataSet(
"StEEmcDb");
122 LOG_INFO <<Form(
"Eemc::Init() MC_flag=%d, config: flag=%d, path=%s=",mMCflag, mConfig,mSetupPath.Data())<<endm;
123 assert(mConfig>=kOnlyAdc);
124 assert(mConfig<=kAdcCompareTrig);
131 StEemcTriggerSimu::addTriggerList(vector<int>& trgList){
134 if(dsm2TreeADC->getOutEndcapHTTP1bit()) {
136 trgList.push_back(117580);
137 trgList.push_back(127580);
138 trgList.push_back(137581);
139 trgList.push_back(117641);
140 trgList.push_back(127641);
141 trgList.push_back(137641);
142 trgList.push_back(117831);
143 trgList.push_back(127831);
144 trgList.push_back(137831);
145 trgList.push_back(137832);
147 trgList.push_back(147580);
148 trgList.push_back(147641);
150 if(dsm2TreeADC->getOutEndcapJP2bit()>=1) trgList.push_back(127551);
151 if(dsm2TreeADC->getOutEndcapJP2bit()>=2) trgList.push_back(127271);
152 if(dsm2TreeADC->getOutEndcapJP2bit()>=1 && dsm2TreeADC->getOutEtot1bit()) trgList.push_back(127652);
155 else if( mYear == 2009 ){
165 StTriggerSimuDecision
167 if (find(mTriggerIds.begin(),mTriggerIds.end(),trigId) == mTriggerIds.end())
return kDoNotCare;
175 StEemcTriggerSimu::InitRun(
int runnumber){
177 memset(ped,0,
sizeof(ped));
178 memset(gain,0,
sizeof(gain));
179 memset(feePed,0,
sizeof(feePed));
180 memset(feeMask,0xff,
sizeof(feeMask));
183 const TDatime& dbtime = StMaker::GetChain()->GetDBTime();
184 mYear = dbtime.GetYear();
185 int yyyymmdd = dbtime.GetDate();
186 int hhmmss = dbtime.GetTime();
188 LOG_INFO<<Form(
"Eemc::InitRun() yyyymmdd=%d hhmmss=%06d\n", yyyymmdd, hhmmss )<<endm;
190 fill(highTowerMask,highTowerMask+90,1);
191 fill(patchSumMask,patchSumMask+90,1);
193 #if 0 // loading local mask files - no actual effect for jobs running on clusters - working on DB solution
194 EemcTrigUtil::getFeeOutMask(dbtime,highTowerMask,patchSumMask);
195 EemcTrigUtil::getFeeBoardMask(dbtime,highTowerMask);
200 LOG_INFO <<
"Using EEMC ONLINE pedestals" << endm;
201 EemcTrigUtil::getFeePed4(dbtime,mxChan,feePed);
205 LOG_INFO <<
"Using EEMC OFFLINE pedestals" << endm;
207 for (
int crate = 1; crate <= mxCr; ++crate) {
208 for (
int chan = 0; chan < mxChan; ++chan) {
209 const EEmcDbItem* x = mDbE->getByCrate(crate,chan);
211 int rdo = getRdo(crate,chan);
214 feePed[rdo] = computePed4(x->ped);
220 LOG_INFO <<
"Using EEMC LOCAL pedestals from file " << mPedFile << endm;
221 ifstream pedfile(mPedFile);
223 int crate, chan, iped;
225 while (pedfile >> crate >> chan >> fped >> iped) {
226 int rdo = getRdo(crate,chan);
234 LOG_INFO <<
"rdo\tcr\tchan\tsta\tped\tped4\tgain" << endm;
236 for (
int crate = 1; crate <= mxCr; ++crate) {
237 for (
int chan = 0; chan < 120; ++chan) {
238 int rdo = getRdo(crate,chan);
239 LOG_INFO << rdo <<
'\t' << crate <<
'\t' << chan <<
'\t' << feeMask[rdo] <<
'\t' << ped[rdo] <<
'\t' << feePed[rdo] <<
'\t' << gain[rdo] << endm;
245 if(!mExternDsmSetup) {
246 EemcTrigUtil::getDsmThresholds( yyyymmdd, hhmmss, thresholds );
248 LOG_INFO<<Form(
"Eemc::InitRun() use externalDSM setup")<<endm;
250 for(i=0;i<nThr;i++) thresholds.HT[i]=mExternDsmSetup[0+i];
251 for(i=0;i<nThr;i++) thresholds.TP[i]=mExternDsmSetup[3+i];
252 for(i=0;i<nThr;i++) thresholds.JP[i]=mExternDsmSetup[6+i];
253 thresholds.TPthrSelc =mExternDsmSetup[9];
254 thresholds.HTTPselect =mExternDsmSetup[10];
255 thresholds.JPSIthrSelc =mExternDsmSetup[11];
256 thresholds.BarreSide =mExternDsmSetup[12];
257 thresholds.BEsumthr =mExternDsmSetup[13];
258 thresholds.EEsumthr =mExternDsmSetup[14];
259 thresholds.EtotThr =mExternDsmSetup[15];
262 LOG_INFO<<Form(
"Eemc::DSM setup HTthr: %d, %d, %d",thresholds.HT[0],thresholds.HT[1],thresholds.HT[2])<<endm;
263 LOG_INFO<<Form(
"Eemc::DSM setup TPthr: %d, %d, %d",thresholds.TP[0],thresholds.TP[1],thresholds.TP[2])<<endm;
264 LOG_INFO<<Form(
"Eemc::DSM setup JPthr: %d, %d, %d",thresholds.JP[0],thresholds.JP[1],thresholds.JP[2])<<endm;
265 LOG_INFO<<Form(
"Eemc::DSM setup BEsumthr=%d, EEsumthr=%d, EtotThr=%d",thresholds.BEsumthr,thresholds.EEsumthr,thresholds.EtotThr)<<endm;
266 LOG_INFO<<Form(
"Eemc::DSM setup TPthrSelc=%d, HTTPthrSelc=%d, JPSIthrSelc=%d, BarreSide=%d",thresholds.TPthrSelc,thresholds.HTTPselect,thresholds.JPSIthrSelc,thresholds.BarreSide)<<endm;
268 dsm0TreeADC->setYear(mYear,thresholds.HT,thresholds.TP);
269 dsm0TreeTRG->setYear(mYear,thresholds.HT,thresholds.TP);
271 dsm1TreeADC->setYear(mYear,thresholds.JP,thresholds.TPthrSelc,thresholds.HTTPselect);
272 dsm1TreeTRG->setYear(mYear,thresholds.JP,thresholds.TPthrSelc,thresholds.HTTPselect);
274 dsm2TreeTRG->setYear(mYear,thresholds.BEsumthr,thresholds.EEsumthr,thresholds.JPSIthrSelc,thresholds.BarreSide,thresholds.EtotThr);
275 dsm2TreeADC->setYear(mYear,thresholds.BEsumthr,thresholds.EEsumthr,thresholds.JPSIthrSelc,thresholds.BarreSide,thresholds.EtotThr);
277 dsm3TRG->setYear(mYear);
282 else if (mYear >= 2009) {
284 if(mYear == 2009 || mYear == 2010 || mYear == 2011 || mYear == 2012 || mYear == 2014 || mYear == 2015 || mYear == 2016){
287 }
else if(mYear == 2013){
289 if(runnumber >= 14081067){
294 }
else if(mYear == 2017){
304 EemcTrigUtil::getDsmThresholds( yyyymmdd, hhmmss, thresholds );
306 LOG_INFO<<Form(
"Eemc::DSM setup HTthr: %d, %d, %d",thresholds.HT[0],thresholds.HT[1])<<endm;
307 LOG_INFO<<Form(
"Eemc::DSM setup JPthr: %d, %d, %d",thresholds.JP[0],thresholds.JP[1],thresholds.JP[2])<<endm;
309 for (
int i = 0; i < 2; ++i) mE001->setRegister(i,thresholds.HT[i]);
310 for (
int i = 0; i < 3; ++i) mE101->setRegister(i,thresholds.JP[i]);
321 StEemcTriggerSimu::Make(){
331 std::vector<unsigned int> trgL=(tic->nominal()).triggerIds();
334 for(ii=0;ii<trgL.size();ii++){
335 TString cID=Form(
"%d",trgL[ii]);
336 hA[1]->Fill(cID.Data(),1.);
342 if(mTestMode && !mMCflag){
343 LOG_DEBUG<<
" TEST Mode"<<endm;
346 for(
int ip = 0; ip < 90; ip++){
347 ht[ip] = emc.highTowerEndcap(ip);
348 pa[ip] = emc.patchEndcap(ip);
350 feeTPTreeADC->test(pa, ht);
353 feeTPTreeADC->compute(rawAdc,feePed,feeMask,highTowerMask,patchSumMask);
357 LOG_DEBUG <<
"EEMC trigger patch format is HT/TPsum" << endm;
358 for (
int dsm = 0; dsm < 9; ++dsm) {
359 TString line = Form(
"TP%d-%d: ",dsm*10,dsm*10+9);
360 for (
int ch = 0; ch < 10; ++ch) {
361 int triggerPatch = dsm*10+ch;
362 line += Form(
"%d/%d ",feeTPTreeADC->TP(triggerPatch)->getOutHT(),feeTPTreeADC->TP(triggerPatch)->getOutTPsum());
364 LOG_DEBUG << line << endm;
374 for(i=0;i<EEfeeTPTree::mxTP;i++) {
375 dsm0TreeADC->setInp12bit(i,feeTPTreeADC->TP(i)->getOut12bit());
377 dsm0TreeADC->compute();
381 for(j=0;j<EEdsm0Tree::Nee0out;j++) {
382 int k = EEdsm1Tree::Nee1BoardInpCha;
385 dsm1TreeADC->setInp16bit(brd, cha, dsm0TreeADC->getOut16bit(j));
387 dsm1TreeADC->compute();
390 dsm2TreeADC->setInput16bit(0, 0, dsm1TreeADC->getOut16bit(0));
391 dsm2TreeADC->setInput16bit(0, 1, dsm1TreeADC->getOut16bit(1));
393 #if 0 // waits for Renee's Etot from DSM
395 static const int kA[6]={3,4,5,0,1,2};
397 unsigned short fakeInput=mBemcEsum5bit[kA[j]];
401 dsm2TreeADC->setInput16bit(ibr+1, ich, fakeInput);
404 dsm2TreeADC->compute();
410 if(mMCflag==0 && mConfig>=kAdcAndTrig){
414 dsm0TreeTRG->compute();
415 dsm1TreeTRG->compute();
416 dsm2TreeTRG->compute();
426 if(mConfig>= kAdcCompareTrig) {
427 compareADCfee_TRG0();
440 addTriggerList(mTriggerIds);
447 else if( mYear >= 2009){
453 if (mMCflag) fillStEmcTriggerDetector();
461 bool StEemcTriggerSimu::isCorrupted()
const {
462 for (
int rdo = 0; rdo < mxCr*mxChan; ++rdo)
463 if (rawAdc[rdo])
return false;
471 StEemcTriggerSimu::getHttpInfo(
int tpId,
EemcHttpInfo &httpInfo){
473 int ith=mHTTPthrSelc-1;
474 assert(ith>=0 && ith<nThr);
475 if(tpId<0 or tpId>=EEfeeTPTree::mxTP)
return false;
476 EEfeeTP *TP=feeTPTreeADC->TP(tpId); assert(TP);
477 int TPsum6b=TP->getOutTPsum();
478 if(TPsum6b<mTPthr[ith])
return false;
479 int HT6bit=TP->getOutHT();
480 if(HT6bit<mHTthr[ith])
return false;
482 httpInfo.tpSumDsmAdc=TPsum6b;
483 httpInfo.htwCh=TP->getTranHTchId();
484 httpInfo.htwCr=TP->getCrateID();
485 httpInfo.htwDsmAdc=HT6bit;
494 StEemcTriggerSimu::getEemcAdc(){
496 if (mSource ==
"MuDst") {
502 for (i=0; i< emc->getNEndcapTowerADC(); i++) {
503 int sec,eta,sub,AdcRead;
504 emc->getEndcapTowerADC(i,AdcRead,sec,sub,eta);
507 const EEmcDbItem *x=mDbE->getTile(sec,
'A'+sub-1,eta,
'T');
511 assert(x->crate >= 1 && x->crate <= 6);
512 assert(x->
chan >= 0 && x->
chan < 120);
513 int rdo = getRdo(x->crate,x->
chan);
514 rawAdc[rdo] = AdcRead;
523 else if (mSource ==
"StEvent") {
524 if (
StEvent* event = (
StEvent*)StMaker::GetChain()->GetDataSet(
"StEvent")) {
528 for (
unsigned int sec = 1; sec <= det->numberOfModules(); ++sec) {
529 const StSPtrVecEmcRawHit& hits = det->module(sec)->hits();
530 ntowers += hits.size();
532 for (
size_t i = 0; i < hits.size(); ++i) {
534 char sub = hit->sub()-1+
'A';
535 int eta = hit->eta();
536 int adc = hit->adc();
538 const EEmcDbItem* x = mDbE->getTile(sec,sub,eta,
'T');
540 int rdo = getRdo(x->crate,x->
chan);
545 assert(ntowers == 720);
551 LOG_ERROR <<
"StEemcTriggerSimu - Unknown source \"" << mSource <<
"\"" << endm;
558 int StEemcTriggerSimu::computePed4(
float ped)
598 ped = (22-int(ped))/4.0;
600 ped = (25-int(ped))/4.0;
608 StEemcTriggerSimu::getDsm0123inputs(){
625 for(i=0;i<EEfeeTPTree::mxTP;i++) {
626 int HT=emcTrgDet.highTowerEndcap(i) &0x3f ;
627 int TP=emcTrgDet.patchEndcap(i) &0x3f;
628 dsm0TreeTRG->setInp12bit(i,((TP<<6)+HT));
633 int mNEemcLayer1 = 16, mNEmcLayer2 = 8;
635 for(i=0;i<mNEemcLayer1;i++) {
636 unsigned short x=emcTrgDet.eemcLayer1(i);
637 printf(
"DSM L1: i=%d val=%d \n",i,x);
639 for(i=0;i<mNEmcLayer2;i++) {
640 unsigned short x=emcTrgDet.emcLayer2(i);
641 printf(
"DSM L2: i=%d val=%d \n",i,x);
646 for(i=0;i<dsm1TreeTRG->getNboards();i++) {
647 dsm1TreeTRG->setInp16bit(i+1,0,emcTrgDet.eemcLayer1(3+i*8));
648 dsm1TreeTRG->setInp16bit(i+1,1,emcTrgDet.eemcLayer1(2+i*8));
649 dsm1TreeTRG->setInp16bit(i+1,2,emcTrgDet.eemcLayer1(1+i*8));
650 dsm1TreeTRG->setInp16bit(i+1,3,emcTrgDet.eemcLayer1(0+i*8));
651 dsm1TreeTRG->setInp16bit(i+1,4,emcTrgDet.eemcLayer1(7+i*8));
652 dsm1TreeTRG->setInp16bit(i+1,5,emcTrgDet.eemcLayer1(6+i*8));
656 dsm2TreeTRG->setInput16bit(0,0,emcTrgDet.emcLayer2(5));
657 dsm2TreeTRG->setInput16bit(0,1,emcTrgDet.emcLayer2(4));
659 dsm2TreeTRG->setInput16bit(1,0,emcTrgDet.emcLayer2(3));
660 dsm2TreeTRG->setInput16bit(1,1,emcTrgDet.emcLayer2(2));
661 dsm2TreeTRG->setInput16bit(2,0,emcTrgDet.emcLayer2(1));
662 dsm2TreeTRG->setInput16bit(2,1,emcTrgDet.emcLayer2(0));
663 dsm2TreeTRG->setInput16bit(3,0,emcTrgDet.emcLayer2(7));
664 dsm2TreeTRG->setInput16bit(3,1,emcTrgDet.emcLayer2(6));
670 unsigned short L0word=L0trg.lastDsmArray(0);
671 dsm3TRG->setWord(0, L0word);
676 printf(
"Dump of real DSM0 inputs, HT:");
677 for(i=0;i<mxTP;i++) {
679 printf(
"\nTPch=%2d ",i);
684 printf(
"%3d ",dsm0inHT[i]);
686 printf(
"Dump of real DSM0 inputs, TPsum:");
687 for(i=0;i<mxTP;i++) {
689 printf(
"\nTPch=%2d ",i);
694 printf(
"%3d ",dsm0inTPsum[i]);
738 StEemcTriggerSimu::getEemcFeeMask() {
740 for (
int icr = 0; icr < 6; ++icr) {
741 for(
int ich = 0; ich < mxChan; ++ich) {
742 const EEmcDbItem *x = mDbE->getByCrate(icr+1,ich);
744 bool killIt = (x->stat & EEMCSTAT_HOTHT) || (x->fail & EEMCFAIL_GARBG);
745 if (killIt) x->print();
746 int rdo = getRdo(x->crate,ich);
747 feeMask[rdo] = killIt;
748 LOG_DEBUG << Form(
"crate=%d chan=%d rdo=%d name=%s tube=%s sec=%d sub=%c eta=%d stat=0x%04x fail=0x%04x killIt=%d ped=%f",
749 x->crate,x->
chan,rdo,x->
name,x->
tube,x->sec,x->sub,x->eta,x->stat,x->fail,killIt,x->ped) << endm;
760 StEemcTriggerSimu::get2009_DSMLayer0(){
761 for(
size_t dsm = 0; dsm < mE001->size(); dsm++ ){
762 TString line = (*mE001)[dsm].name +
": ";
763 for(
int ch = 0; ch < 10; ch++ ){
764 Int_t tpid = dsm * 10 + ch;
765 (*mE001)[dsm].channels[ch] = feeTPTreeADC->TP(tpid)->getOut12bit();
766 line += Form(
"%04x ",(*mE001)[dsm].channels[ch]);
768 LOG_DEBUG << line << endm;
775 StEemcTriggerSimu::get2009_DSMLayer1(){
776 mE001->write(*mE101);
778 for (
size_t dsm = 0; dsm < mE101->size(); ++dsm) {
779 TString line = (*mE101)[dsm].name +
": ";
780 for (
int ch = 0; ch < 8; ++ch) line += Form(
"%04x ",(*mE101)[dsm].channels[ch]);
781 LOG_DEBUG << line << endm;
791 int StEemcTriggerSimu::endcapJetPatchTh(
int i)
const {
return mE101->getRegister(i); }
792 int StEemcTriggerSimu::endcapHighTowerTh(
int i)
const {
return mE001->getRegister(i); }
794 int StEemcTriggerSimu::endcapJetPatchAdc(
int jp)
const {
return (*mE101)[1-jp/3].info[jp%3]; }
795 int StEemcTriggerSimu::endcapPartialJetPatchAdc(
int jp)
const {
return (*mE101)[1-jp/3].info[3+jp%3]; }
797 int StEemcTriggerSimu::getOutHT(
int tp)
const {
return feeTPTreeADC->TP(tp)->getOutHT(); }
798 int StEemcTriggerSimu::getOutTPsum(
int tp)
const {
return feeTPTreeADC->TP(tp)->getOutTPsum(); }
803 void StEemcTriggerSimu::fillStEmcTriggerDetector()
805 StEvent*
event = (
StEvent*)StMaker::GetChain()->GetDataSet(
"StEvent");
806 if (event && event->triggerDetectorCollection()) {
808 for (
int triggerPatch = 0; triggerPatch < 90; ++triggerPatch) {
809 emc.setHighTowerEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutHT());
810 emc.setPatchEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutTPsum());
815 for (
int triggerPatch = 0; triggerPatch < 90; ++triggerPatch) {
816 emc.setHighTowerEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutHT());
817 emc.setPatchEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutTPsum());
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
StTriggerSimuDecision triggerDecision(int trigId)
like isTrigger(), but returns kDoNotCare if detector isn't a part of the given trigId ...
char tube[StEEmcNameLen]
name of PMT or MAPMT pixel
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Collection of trigger ids as stored in MuDst.