StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEemcTriggerSimu.cxx
1 //
2 // StEemcTriggerSimu.cxx,v 0.01
3 //
4 /*
5  changes to be done in bbc-code, Jan
6  - add TDC limits for real data
7  - add histos for all PMTs
8 */
9 
10 #include <TH2.h>
11 #include <StMessMgr.h>
12 
13 #include "StEemcTriggerSimu.h"
14 #include "EemcHttpInfo.h"
15 
16 #include "StEvent/StEvent.h"
17 #include "StEvent/StEventTypes.h"
18 #include "StEvent/StEmcTriggerDetector.h"
19 #include "StEvent/StL0Trigger.h"
20 
21 
22 //MuDst
23 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
24 #include "StMuDSTMaker/COMMON/StMuDst.h"
25 #include "StMuDSTMaker/COMMON/StMuEvent.h"
26 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
27 
28 #include "St_db_Maker/St_db_Maker.h"
29 
30 // ETOW stuff
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>
35 
36 
37 #include "EEfeeTPTree.h"
38 #include "EEfeeTP.h"
39 #include "EEdsm0Tree.h"
40 #include "EEdsm1Tree.h"
41 #include "EMCdsm2Tree.h"
42 #include "EEdsm3.h"
43 #include "EemcTrigUtil.h"
44 
45 // #### modified by Liaoyuan ####
46 // DSM 2009 Utilities
47 #include "StTriggerUtilities/StDSMUtilities/StDSM2009Utilities.hh"
48 // #### modified end ####
49 
50 
51 ClassImp(StEemcTriggerSimu);
52 
53 //==================================================
54 //==================================================
55 
56 StEemcTriggerSimu::StEemcTriggerSimu() {
57  // printf("The StEemcTriggerSimu constructor\n");
58  mPedMode = kOffline;
59  nInpEve=0;
60  mHList=0;
61  mDbE=0;
62  mBemcEsum5bit=0;
63  mExternDsmSetup=0;
64  mSetupPath="wrong1";
65 
66  feeTPTreeADC=new EEfeeTPTree("ADC",mxChan);
67  dsm0TreeADC =new EEdsm0Tree("ADC");
68  dsm1TreeADC =new EEdsm1Tree("ADC");
69  dsm2TreeADC =new EMCdsm2Tree("ADC");
70 
71  // only for QA
72  dsm0TreeTRG =new EEdsm0Tree("TRG");
73  dsm1TreeTRG =new EEdsm1Tree("TRG");
74  dsm2TreeTRG =new EMCdsm2Tree("TRG");
75  dsm3TRG =new EEdsm3();
76 
77  mTestMode = false;
78  LOG_INFO <<"Eemc::constructor"<<endm;
79 }
80 
81 //==================================================
82 //==================================================
83 
84 StEemcTriggerSimu::~StEemcTriggerSimu()
85 {
86  delete mE001; mE001 = 0;
87  delete mE101; mE101 = 0;
88 }
89 
90 //==================================================
91 //==================================================
92 void
93 StEemcTriggerSimu::Clear(){
94 
95  // printf("This is StEemcTriggerSimu::Clear\n");
96  memset(rawAdc,0,sizeof(rawAdc));
97  feeTPTreeADC->clear();
98  dsm0TreeADC->clear();
99  dsm1TreeADC->clear();
100  dsm2TreeADC->clear();
101 
102  // always clear, despite of setup
103  dsm0TreeTRG->clear();
104  dsm1TreeTRG->clear();
105  dsm2TreeTRG->clear();
106  dsm3TRG->clear();
107 
108  mTriggerIds.clear();
109 }
110 
111 //==================================================
112 //==================================================
113 
114 void
115 StEemcTriggerSimu::Init(){
116 
117  mYear=-888;
118  //................EEMC stuff ..............
119  mDbE = (StEEmcDb*)StMaker::GetChain()->GetDataSet("StEEmcDb");
120  assert(mDbE);
121  // assert( mBemcEsum5bit);
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);
125 }
126 
127 //==================================================
128 //==================================================
129 
130 void
131 StEemcTriggerSimu::addTriggerList(vector<int>& trgList){
132  if(mYear==2006) {
133  //fix it if( yymmdd<20060408 || yymmdd>20060414) return;
134  if(dsm2TreeADC->getOutEndcapHTTP1bit()) {
135  // pp 200 GeV running
136  trgList.push_back(117580); // eemc-http
137  trgList.push_back(127580); // eemc-http
138  trgList.push_back(137581); // eemc-http
139  trgList.push_back(117641); // eemc-http-mb-L2gamma
140  trgList.push_back(127641); // eemc-http-mb-L2gamma
141  trgList.push_back(137641); // eemc-http-mb-L2gamma
142  trgList.push_back(117831); // eemc-http-mb-fast
143  trgList.push_back(127831); // eemc-http-mb-fast
144  trgList.push_back(137831); // eemc-http-mb-fast
145  trgList.push_back(137832); // eemc-http-mb-fast
146  // pp 62 GeV running
147  trgList.push_back(147580); // eemc-http
148  trgList.push_back(147641); // eemc-http-mb-l2gamma
149  }
150  if(dsm2TreeADC->getOutEndcapJP2bit()>=1) trgList.push_back(127551);//EJP0,add mising mb
151  if(dsm2TreeADC->getOutEndcapJP2bit()>=2) trgList.push_back(127271);
152  if(dsm2TreeADC->getOutEndcapJP2bit()>=1 && dsm2TreeADC->getOutEtot1bit()) trgList.push_back(127652);
153  }
154  // #### modified by Liaoyuan ####
155  else if( mYear == 2009 ){
156  ; // Triggers-Ids are Generated in StEmcTriggerSimu instead
157  }
158  // #### modified end ####
159 
160 }
161 
162 //==================================================
163 //==================================================
164 
165 StTriggerSimuDecision
167  if (find(mTriggerIds.begin(),mTriggerIds.end(),trigId) == mTriggerIds.end()) return kDoNotCare;
168  return kYes;
169 }
170 
171 //==================================================
172 //==================================================
173 
174 void
175 StEemcTriggerSimu::InitRun(int runnumber){
176 
177  memset(ped,0,sizeof(ped));
178  memset(gain,0,sizeof(gain));
179  memset(feePed,0,sizeof(feePed));
180  memset(feeMask,0xff,sizeof(feeMask)); // mask everything as bad
181  getEemcFeeMask(); // get offline mask
182 
183  const TDatime& dbtime = StMaker::GetChain()->GetDBTime();
184  mYear = dbtime.GetYear();
185  int yyyymmdd = dbtime.GetDate(); //form of 19971224 (i.e. 24/12/1997)
186  int hhmmss = dbtime.GetTime(); //form of 123623 (i.e. 12:36:23)
187 
188  LOG_INFO<<Form("Eemc::InitRun() yyyymmdd=%d hhmmss=%06d\n", yyyymmdd, hhmmss )<<endm;
189 
190  fill(highTowerMask,highTowerMask+90,1); // all channels good
191  fill(patchSumMask,patchSumMask+90,1); // all channels good
192 
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);
196 #endif
197 
198  switch (mPedMode) {
199  case kOnline:
200  LOG_INFO << "Using EEMC ONLINE pedestals" << endm;
201  EemcTrigUtil::getFeePed4(dbtime,mxChan,feePed);
202  break;
203 
204  case kOffline:
205  LOG_INFO << "Using EEMC OFFLINE pedestals" << endm;
206  assert(mDbE);
207  for (int crate = 1; crate <= mxCr; ++crate) {
208  for (int chan = 0; chan < mxChan; ++chan) {
209  const EEmcDbItem* x = mDbE->getByCrate(crate,chan);
210  if (!x) continue; // skip not mapped channels
211  int rdo = getRdo(crate,chan);
212  ped[rdo] = x->ped;
213  gain[rdo] = x->gain;
214  feePed[rdo] = computePed4(x->ped);
215  } // for chan
216  } // for crate
217  break;
218 
219  case kLocal:
220  LOG_INFO << "Using EEMC LOCAL pedestals from file " << mPedFile << endm;
221  ifstream pedfile(mPedFile);
222  assert(pedfile);
223  int crate, chan, iped;
224  float fped;
225  while (pedfile >> crate >> chan >> fped >> iped) {
226  int rdo = getRdo(crate,chan);
227  ped[rdo] = fped;
228  feePed[rdo] = iped;
229  }
230  pedfile.close();
231  break;
232  }
233 
234  LOG_INFO << "rdo\tcr\tchan\tsta\tped\tped4\tgain" << endm;
235 
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;
240  }
241  }
242 
243  if( mYear == 2006 ){ // #### modified line by Liaoyuan
244  DsmThreshold thresholds;
245  if(!mExternDsmSetup) {
246  EemcTrigUtil::getDsmThresholds( yyyymmdd, hhmmss, thresholds );
247  } else {
248  LOG_INFO<<Form("Eemc::InitRun() use externalDSM setup")<<endm;
249  int i;
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];
260  }
261 
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;
267 
268  dsm0TreeADC->setYear(mYear,thresholds.HT,thresholds.TP);
269  dsm0TreeTRG->setYear(mYear,thresholds.HT,thresholds.TP);
270 
271  dsm1TreeADC->setYear(mYear,thresholds.JP,thresholds.TPthrSelc,thresholds.HTTPselect);
272  dsm1TreeTRG->setYear(mYear,thresholds.JP,thresholds.TPthrSelc,thresholds.HTTPselect);
273 
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);
276 
277  dsm3TRG->setYear(mYear);
278 
279  initHisto();
280  } // #### modified line by Liaoyuan
281  // #### modified by Liaoyuan ####
282  else if (mYear >= 2009) {
283  // 2009
284  if(mYear == 2009 || mYear == 2010 || mYear == 2011 || mYear == 2012 || mYear == 2014 || mYear == 2015 || mYear == 2016){
285  mE001 = new DSMLayer_E001_2009;
286  mE101 = new DSMLayer_E101_2009;
287  }else if(mYear == 2013){
288  mE001 = new DSMLayer_E001_2009;
289  if(runnumber >= 14081067){
290  mE101 = new DSMLayer_E101_2013;
291  }else{
292  mE101 = new DSMLayer_E101_2009;
293  }
294  }else if(mYear == 2017){
295  mE001 = new DSMLayer_E001_2017;
296  mE101 = new DSMLayer_E101_2017;
297  }else{
298  mE001 = new DSMLayer_E001_2009;
299  mE101 = new DSMLayer_E101_2009;
300  }
301 
302 #if 0
303  DsmThreshold thresholds;
304  EemcTrigUtil::getDsmThresholds( yyyymmdd, hhmmss, thresholds );
305 
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;
308 
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]);
311 #endif
312 
313  }
314  // #### modified end ####
315 }
316 
317 //==================================================
318 //==================================================
319 
320 void
321 StEemcTriggerSimu::Make(){
322  nInpEve++;
323  mDumpEve=eveId%1==0;
324 
325 #if 0
326  assert(mMCflag==0); // not sure what will it do for MC
327  StEventInfo &info=StMuDst::event()->eventInfo();
328  // mEleT->info.zVertex=ver.z();
329  eveId=info.id();
330  StMuTriggerIdCollection *tic=&StMuDst::event()->triggerIdCollection();
331  std::vector<unsigned int> trgL=(tic->nominal()).triggerIds();
332  // printf(" trigL len=%d \n",trgL.size());
333  unsigned int ii;
334  for(ii=0;ii<trgL.size();ii++){ // collect all trigger ID's
335  TString cID=Form("%d",trgL[ii]);
336  hA[1]->Fill(cID.Data(),1.);
337  }
338 #endif
339 
340  // ************** Emulation of trigger based on ADC ************
341  //start zchang
342  if(mTestMode && !mMCflag){
343  LOG_DEBUG<<" TEST Mode"<<endm;
344  StEmcTriggerDetector emc = StMuDst::event()->emcTriggerDetector();
345  int ht[90], pa[90];
346  for(int ip = 0; ip < 90; ip++){
347  ht[ip] = emc.highTowerEndcap(ip);
348  pa[ip] = emc.patchEndcap(ip);
349  }
350  feeTPTreeADC->test(pa, ht);
351  }else{
352  getEemcAdc(); // processed raw ADC
353  feeTPTreeADC->compute(rawAdc,feePed,feeMask,highTowerMask,patchSumMask);
354  }
355  //end zchang
356  // LOG_DEBUG messages
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());
363  }
364  LOG_DEBUG << line << endm;
365  }
366 
367  if( mYear == 2006 ){ // #### modified line by Liaoyuan
368 
369 
370  int i;
371  // for(i=0;i<90;i++) feeTPTreeADC->TP(i)->print(3); // prints FEE output for 720 towers
372 
373  // printf("...... populate inputs of dsm0TreeADC...\n");
374  for(i=0;i<EEfeeTPTree::mxTP;i++) {
375  dsm0TreeADC->setInp12bit(i,feeTPTreeADC->TP(i)->getOut12bit());
376  }
377  dsm0TreeADC->compute();
378  // if(mDumpEve) dsm0TreeADC->print();
379 
380  int j;
381  for(j=0;j<EEdsm0Tree::Nee0out;j++) {
382  int k = EEdsm1Tree::Nee1BoardInpCha;
383  int brd = j/k+1;
384  int cha = j%k;
385  dsm1TreeADC->setInp16bit(brd, cha, dsm0TreeADC->getOut16bit(j));
386  }
387  dsm1TreeADC->compute();
388 
389  // Endcap DSM2 (1 board), all information
390  dsm2TreeADC->setInput16bit(0, 0, dsm1TreeADC->getOut16bit(0));
391  dsm2TreeADC->setInput16bit(0, 1, dsm1TreeADC->getOut16bit(1));
392 
393 #if 0 // waits for Renee's Etot from DSM
394  // Barrel DSM2 (3 boards), only 5bit Esum for 6 remaining inputs
395  static const int kA[6]={3,4,5,0,1,2}; // mapping between Renee & Hank
396  for(j=0;j<6;j++) {
397  unsigned short fakeInput=mBemcEsum5bit[kA[j]]; //DSM 5bit ADC
398  // higher bits ar not provided for the Barrel
399  int ibr=j/2;
400  int ich=j%2;
401  dsm2TreeADC->setInput16bit(ibr+1, ich, fakeInput);
402  }
403 #endif
404  dsm2TreeADC->compute();
405 
406 
407 
408  // *********** END of Emulation of trigger based on ADC ************
409 
410  if(mMCflag==0 && mConfig>=kAdcAndTrig){
411  // acquire true DSM values only for real events
412  //........... QA of online trigger data ...............
413  getDsm0123inputs(); // this tree contains trigger data
414  dsm0TreeTRG->compute();
415  dsm1TreeTRG->compute();
416  dsm2TreeTRG->compute();
417 
418 
419  //if(mDumpEve) dsm0TreeTRG->print();
420  //if(mDumpEve) dsm1TreeTRG->print();
421  //if(mDumpEve) dsm2TreeTRG->print();
422  //if(mDumpEve) dsm3TRG->print();
423 
424  //dsm2TreeADC->print();
425  //dsm2TreeTRG->print();
426  if(mConfig>= kAdcCompareTrig) {
427  compareADCfee_TRG0();
428  compareADC0_TRG1();
429  compareADC1_TRG2();
430  compareADC2_TRG3();
431 
432  compareTRG0_TRG1();
433  compareTRG1_TRG2();
434  compareTRG2_TRG3();
435  }
436  }
437 
438  DSM2EsumSpectra();
439 
440  addTriggerList(mTriggerIds);
441 
442  // dsm2TreeADC->print(0);
443 
444  //if(mDumpEve) printf("\nzzzzz===================================================\n\n");
445  }// #### modified line by Liaoyuan
446  // #### modified by Liaoyuan ####
447  else if( mYear >= 2009){
448  get2009_DSMLayer0();
449  get2009_DSMLayer1();
450  }
451  // #### modified end ####
452 
453  if (mMCflag) fillStEmcTriggerDetector();
454 }
455 
456 //==================================================
457 //==================================================
458 
459 // All tower ADCs are set to zero for corrupted events
460 
461 bool StEemcTriggerSimu::isCorrupted() const {
462  for (int rdo = 0; rdo < mxCr*mxChan; ++rdo)
463  if (rawAdc[rdo]) return false;
464  return true;
465 }
466 
467 //==================================================
468 //==================================================
469 
470 bool
471 StEemcTriggerSimu::getHttpInfo(int tpId, EemcHttpInfo &httpInfo){
472  httpInfo.clear();
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;
481  httpInfo.tpId=tpId;
482  httpInfo.tpSumDsmAdc=TPsum6b;
483  httpInfo.htwCh=TP->getTranHTchId();
484  httpInfo.htwCr=TP->getCrateID();
485  httpInfo.htwDsmAdc=HT6bit;
486  return true;
487 
488 }
489 
490 //==================================================
491 //==================================================
492 
493 void
494 StEemcTriggerSimu::getEemcAdc(){
495  // printf("This StEemcTriggerSimu::getting Endcap ADC values\n");
496  if (mSource == "MuDst") {
498  // printf("see %d endcap towers\n",emc->getNEndcapTowerADC());
499 
500  //......................... T O W E R S .....................
501  int i;
502  for (i=0; i< emc->getNEndcapTowerADC(); i++) {
503  int sec,eta,sub,AdcRead; //muDst ranges:sec:1-12, sub:1-5, eta:1-12
504  emc->getEndcapTowerADC(i,AdcRead,sec,sub,eta);
505 
506  //Db ranges: sec=1-12,sub=A-E,eta=1-12,type=T,P-R ; slow method
507  const EEmcDbItem *x=mDbE->getTile(sec,'A'+sub-1,eta,'T');
508  assert(x); // it should never happened for muDst
509  // do NOT drop not working channels
510 
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;
515 
516  //LOG_DEBUG << Form("crate=%d chan=%d rdo=%d adc=%d",x->crate,x->chan,rdo,AdcRead) << endm;
517 
518  //if(strstr(x->name,"12TD03")) printf("i=%d, name=%s, sec=%d, crate=%d, chan=%d, ped=%.1f, rawADC=%d\n",i, x->name, sec, x->crate, x->chan, x->ped, AdcRead);
519  // if(x->crate==2) printf(" name=%s crate=%d, chan=%d ped=%.1f rawADC=%d stat=%d fail=%d\n", x->name, x->crate, x->chan, x->ped, AdcRead, x->stat, x->fail);
520  } // end of loop over towers
521  } // if (emc)
522  }
523  else if (mSource == "StEvent") { // Useful for running in BFC
524  if (StEvent* event = (StEvent*)StMaker::GetChain()->GetDataSet("StEvent")) {
525  if (StEmcCollection* emc = event->emcCollection()) {
526  if (StEmcDetector* det = emc->detector(kEndcapEmcTowerId)) {
527  int ntowers = 0;
528  for (unsigned int sec = 1; sec <= det->numberOfModules(); ++sec) { // 1-12
529  const StSPtrVecEmcRawHit& hits = det->module(sec)->hits();
530  ntowers += hits.size();
531  //LOG_DEBUG << Form("sector=%d: nhits=%d",sec,hits.size()) << endm;
532  for (size_t i = 0; i < hits.size(); ++i) {
533  const StEmcRawHit* hit = hits[i];
534  char sub = hit->sub()-1+'A'; // 'A'-'E'
535  int eta = hit->eta(); // 1-12
536  int adc = hit->adc(); // raw ADC
537  // Db ranges: sector=1-12,sub=A-E,eta=1-12,type=T,P-R; slow method
538  const EEmcDbItem* x = mDbE->getTile(sec,sub,eta,'T');
539  if (!x) continue;
540  int rdo = getRdo(x->crate,x->chan);
541  rawAdc[rdo] = adc;
542  //LOG_DEBUG << Form("crate=%d chan=%d rdo=%d adc=%d",x->crate,x->chan,rdo,adc) << endm;
543  } // End loop over hits
544  } // End loop over sectors
545  assert(ntowers == 720);
546  } // if (det)
547  } // if (emc)
548  } // if (event)
549  }
550  else {
551  LOG_ERROR << "StEemcTriggerSimu - Unknown source \"" << mSource << "\"" << endm;
552  }
553 }
554 
555 //==================================================
556 //==================================================
557 
558 int StEemcTriggerSimu::computePed4(float ped)
559 {
560  //
561  // def computePed4(self):
562  // ### create btow dictionary (ie arrays) for ped4 and status
563  // '''self.btowPed4 = {}
564  // self.btowStatus = {}
565  // for i in range(6):
566  // self.btowPed4[i] = {}
567  // self.btowPed4[i] = {}
568  // for btower in self.btow:
569  // if btower.pedMean > 24:
570  // ped4 = (22-int(btower.pedMean))/4
571  // else:
572  // ped4 = (25-int(btower.pedMean))/4
573  // btower.ped4 = int(ped4)
574  // self.btowPed4[btower.crate][btower.channel] = btower.ped4
575  // self.btowStatus[btower.crate][btower.channel] = btower.status'''
576  //
577  // ### create etow dictionary (ie arrays) for ped4 and status
578  // self.etowPed4 = {}
579  // self.etowStatus = {}
580  // self.etowPedMean = {}
581  // for i in range(6):
582  // self.etowPed4[i+1] = {}
583  // self.etowStatus[i+1] = {}
584  // self.etowPedMean[i+1] = {}
585  // for etower in self.etow.values():
586  // roundedPedMean = etower.pedMean+0.5
587  // if roundedPedMean>24:
588  // ped4 = (22-int(roundedPedMean))/4.0
589  // else:
590  // ped4 = (25-int(roundedPedMean))/4.0
591  // etower.ped4 = int(ped4)
592  // self.etowPed4[etower.crate][etower.channel] = etower.ped4
593  // self.etowStatus[etower.crate][etower.channel] = etower.status
594  // self.etowPedMean[etower.crate][etower.channel] = etower.pedMean
595  //
596  ped += 0.5;
597  if (ped > 24)
598  ped = (22-int(ped))/4.0;
599  else
600  ped = (25-int(ped))/4.0;
601  return int(ped);
602 }
603 
604 //==================================================
605 //==================================================
606 
607 void
608 StEemcTriggerSimu::getDsm0123inputs(){
609  /*
610  > unsigned char eemcHighTower(int patch_id, int prepost=0) const;
611  > unsigned char eemcJetPatch (int patch_id, int prepost=0) const;
612  > unsigned char eemcHighestTowerADC(int prepost=0) const;
613  > unsigned char * getDsm0_EEMC(int prepost=0) const;
614  > unsigned short int * getDsm1_EEMC(int prepost=0) const;
615  > unsigned short int * getDsm2_EMC() const;
616  > unsigned short int * getDsm3() const; // lastDSM
617  */
618 
619 
620  // printf("This StEemcTriggerSimu::getting Endcap DSM0 inputs\n");
621 
622  StEmcTriggerDetector &emcTrgDet=StMuDst::event()->emcTriggerDetector();
623 
624  int i;
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));
629  }
630 
631 
632 #if 0
633  int mNEemcLayer1 = 16, mNEmcLayer2 = 8;
634 
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);
638  }
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);
642  }
643 #endif
644 
645 
646  for(i=0;i<dsm1TreeTRG->getNboards();i++) { // loop over DSM1 boards
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));
653  }
654 
655  //Endcap DSM2 (1 board)
656  dsm2TreeTRG->setInput16bit(0,0,emcTrgDet.emcLayer2(5));
657  dsm2TreeTRG->setInput16bit(0,1,emcTrgDet.emcLayer2(4));
658  //Barrel DSM2 (3 boards)
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));
665 
666  //DSM3 (lastDSM)
667  StL0Trigger &L0trg=StMuDst::event()->l0Trigger();
668  //int L0Num;
669  //L0Num=L0trg.lastDsmArraySize();
670  unsigned short L0word=L0trg.lastDsmArray(0);
671  dsm3TRG->setWord(0, L0word);
672  //printf("L0word=%d\n", L0word);
673 
674 
675 #if 0
676  printf("Dump of real DSM0 inputs, HT:");
677  for(i=0;i<mxTP;i++) {
678  if(i%10==0)
679  printf("\nTPch=%2d ",i);
680  else if(i%5==0)
681  printf(" ");
682  else
683  printf(" ");
684  printf("%3d ",dsm0inHT[i]);
685  } printf("\n");
686  printf("Dump of real DSM0 inputs, TPsum:");
687  for(i=0;i<mxTP;i++) {
688  if(i%10==0)
689  printf("\nTPch=%2d ",i);
690  else if(i%5==0)
691  printf(" ");
692  else
693  printf(" ");
694  printf("%3d ",dsm0inTPsum[i]);
695  }
696  printf("\n");
697 #endif
698 }
699 
700 //==================================================
701 //==================================================
702 
703 // Source: StEEmcUtil/database/cstructs/eemcConstDB.hh
704 
705 /*
706 Use idividual bits of 'stat' to exclude individual
707 channels from a particular analysis, but let other
708 analysis make a different choice.
709 */
710 
711 // status bits (short int)
712 /*
713 #define EEMCSTAT_ONLPED 0x0001 // only pedestal is visible
714 #define EEMCSTAT_STKBT 0x0002 // sticky lower bits
715 #define EEMCSTAT_HOTHT 0x0004 // masked for HT trigger
716 #define EEMCSTAT_HOTJP 0x0008 // masked for JP trigger
717 #define EEMCSTAT_HIGPED 0x0010 // ped is very high but channel seems to work
718 #define EEMCSTAT_HOTSTR 0x0020 // hot esmd strip
719 #define EEMCSTAT_JUMPED 0x0040 // jumpy ped over several chan over days
720 #define EEMCSTAT_WIDPED 0x0080 // wide ped over:2.5 ch towers, 1.5 ch MAPMT's
721 */
722 
723 //The remaing bits of 'stat' are free.
724 
725 /* The 'fail' 16-bits are meant as general abort of a given
726 channel.
727 */
728 
729 // failure bits (short int)
730 /*
731 #define EEMCFAIL_GARBG 0x0001 // faulty channel
732 #define EEMCFAIL_HVOFF 0x0002 // HV was off or varied
733 #define EEMCFAIL_NOFIB 0x0004 // signal fiber is broken
734 #define EEMCFAIL_CPYCT 0x0008 // stuck in copyCat mode
735 */
736 
737 void
738 StEemcTriggerSimu::getEemcFeeMask() {
739  assert(mDbE);
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);
743  if (!x) continue; // skip not mapped channels
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;
750  } // end of chan loop
751  }// end of crate loop
752 }
753 
754 //==================================================
755 //==================================================
756 
757 // #### modified by Liaoyuan ####
758 
759 void
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]);
767  }
768  LOG_DEBUG << line << endm;
769  }
770 
771  mE001->run();
772 }
773 
774 void
775 StEemcTriggerSimu::get2009_DSMLayer1(){
776  mE001->write(*mE101);
777 
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;
782  }
783 
784  mE101->run();
785 }
786 
787 // #### modified end ####
788 
789 //==================================================
790 
791 int StEemcTriggerSimu::endcapJetPatchTh(int i) const { return mE101->getRegister(i); }
792 int StEemcTriggerSimu::endcapHighTowerTh(int i) const { return mE001->getRegister(i); }
793 
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]; }
796 
797 int StEemcTriggerSimu::getOutHT(int tp) const { return feeTPTreeADC->TP(tp)->getOutHT(); }
798 int StEemcTriggerSimu::getOutTPsum(int tp) const { return feeTPTreeADC->TP(tp)->getOutTPsum(); }
799 
800 //==================================================
801 //==================================================
802 
803 void StEemcTriggerSimu::fillStEmcTriggerDetector()
804 {
805  StEvent* event = (StEvent*)StMaker::GetChain()->GetDataSet("StEvent");
806  if (event && event->triggerDetectorCollection()) {
807  StEmcTriggerDetector& emc = event->triggerDetectorCollection()->emc();
808  for (int triggerPatch = 0; triggerPatch < 90; ++triggerPatch) {
809  emc.setHighTowerEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutHT());
810  emc.setPatchEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutTPsum());
811  }
812  }
813  if (StMuDst::event()) {
814  StEmcTriggerDetector& emc = StMuDst::event()->emcTriggerDetector();
815  for (int triggerPatch = 0; triggerPatch < 90; ++triggerPatch) {
816  emc.setHighTowerEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutHT());
817  emc.setPatchEndcap(triggerPatch,feeTPTreeADC->TP(triggerPatch)->getOutTPsum());
818  }
819  }
820 }
821 
822 //==================================================
823 //==================================================
824 
825 //
826 // $Log: StEemcTriggerSimu.cxx,v $
827 // Revision 1.54 2020/04/23 02:14:45 zchang
828 // uncomment lines regarding load EEMC FEE mask
829 //
830 // Revision 1.53 2020/04/12 03:56:25 zchang
831 // Add EMC DSM algorithm for the 2017 pp run
832 //
833 // Revision 1.52 2020/01/13 20:45:50 zchang
834 // removing old run13 dsm algo files
835 //
836 // Revision 1.51 2019/05/21 19:27:14 zchang
837 // make changes for the trigger simulator to only use 2013 algorithms for that year, not for later years, later years still use 2009 algorithms
838 //
839 // Revision 1.50 2017/01/02 15:31:56 rfatemi
840 // Updated by Danny OLVITT for 2013 dijet analysiss
841 //
842 // Revision 1.49 2012/08/27 17:16:41 pibero
843 // Add logging of EEMC gains from DB
844 //
845 // Revision 1.48 2012/07/12 09:37:10 pibero
846 // Fix fillStTriggerDetector()
847 //
848 // Revision 1.47 2011/10/22 20:25:17 pibero
849 // Add getters for output of EEMC FEEs for backward-compatibility
850 //
851 // Revision 1.46 2011/10/16 21:43:44 pibero
852 // Implement EEMC FEE boards HT masks
853 //
854 // Revision 1.45 2011/10/16 17:41:59 pibero
855 // Implement EEMC FEE HT & TP masks
856 //
857 // Revision 1.44 2011/10/14 22:33:45 pibero
858 // Add functions to test for data corruption in calorimeters
859 //
860 // Revision 1.43 2011/10/11 09:41:51 pibero
861 // Make sure there are 720 towers in EEMC
862 //
863 // Revision 1.42 2011/09/27 19:23:52 pibero
864 // Added rdo and status
865 //
866 // Revision 1.41 2011/09/22 15:55:21 pibero
867 // Added EEMC pedestal modes:
868 //
869 // kOnline = use online pedestals
870 // kOffline = use offline pedestals
871 // kLocal = use pedestals from a local file (format: crate channel pedestal ped4)
872 //
873 // Revision 1.40 2011/09/22 01:03:12 pibero
874 // Log crate, channel, pedestal and ped4
875 //
876 // Revision 1.39 2011/09/20 13:32:43 pibero
877 // Added support for using EEMC offline pedestals (default)
878 //
879 // Revision 1.38 2010/08/03 15:00:56 rfatemi
880 // revert to kDontCare
881 //
882 // Revision 1.37 2010/07/28 15:58:06 pibero
883 // Code cleanup
884 //
885 // Revision 1.36 2010/07/08 21:21:05 pibero
886 // Changed triggerDecision from kDoNotCare to kNo
887 //
888 // Revision 1.35 2010/07/08 21:00:08 pibero
889 // Removed redundant eemc-http triggers
890 //
891 // Revision 1.34 2010/07/08 20:56:17 pibero
892 // Added a bunch of eemc-http triggers
893 //
894 // Revision 1.33 2010/06/29 16:53:27 pibero
895 // Now, the trigger simulator fills in the StEmcTriggerDetector structure
896 // same as data for MC.
897 //
898 // Revision 1.32 2010/06/24 07:51:21 pibero
899 // Added hooks to overwrite DSM thresholds from the database.
900 //
901 // Revision 1.31 2010/04/16 01:47:46 pibero
902 // Oops, forgot to include triggers before 2009. Thanks, Liaoyuan.
903 //
904 // Revision 1.30 2010/03/01 18:48:42 pibero
905 // More updates for Run 9
906 //
907 // Revision 1.29 2010/02/18 20:07:10 pibero
908 // Run 9 updates
909 //
910 // Revision 1.28 2010/01/08 15:18:39 pibero
911 // Default input source is "MuDst" for all subdetectors.
912 //
913 // Revision 1.27 2010/01/08 06:39:05 pibero
914 // Set default input source to "MuDst" in constructor.
915 //
916 // Revision 1.26 2009/12/22 18:11:05 pibero
917 // Added ability to set input source (MuDst or StEvent) for BBC trigger simulator.
918 //
919 // Revision 1.25 2009/12/15 16:33:33 pibero
920 // Added support to set thresholds manually for Run 9
921 // and overwrite those from the database.
922 //
923 // Revision 1.24 2009/12/08 02:12:42 pibero
924 // Removed extraneous "return;"
925 //
926 // Revision 1.23 2009/12/08 02:06:59 pibero
927 // Add support for StEvent when running in BFC.
928 //
929 // Revision 1.22 2009/12/06 21:57:49 pibero
930 // Removed dependency on hard-coded maker's name.
931 //
932 // Revision 1.21 2009/11/19 07:29:28 pibero
933 // Mask out faulty EEMC towers. Add more LOG_DEBUG messages.
934 //
935 // Revision 1.20 2009/11/18 23:42:50 pibero
936 // More LOG_DEBUG messages...
937 //
938 // Revision 1.19 2009/11/18 19:12:14 pibero
939 // Added Endcap FEE pedestals for all years.
940 // The code will scan the setup directory /afs/rhic.bnl.gov/star/users/pibero/public/StarTrigSimuSetup/ped
941 // and load pedestals from the DB timestamp.
942 // The plan for the future is to upload the ped4 into the STAR database and retrieve from there.
943 //
944 // Revision 1.18 2009/11/16 07:51:56 pibero
945 // Added LOG_DEBUG messages
946 //
947 // Revision 1.17 2009/10/12 18:04:28 pibero
948 // Moved StEEmcUtil/EEdsm to StTriggerUtilities/Eemc
949 //
950 // Revision 1.16 2009/09/26 18:46:37 pibero
951 // Migration from ROOT MySQL to STAR DB API
952 //
953 // Revision 1.15 2009/09/23 22:35:43 pibero
954 // Removed dependencies on ROOT MySQL
955 //
956 // Revision 1.14 2009/09/20 06:46:41 pibero
957 // Updates for Run 9
958 //
959 // Revision 1.13 2009/02/21 19:21:02 pibero
960 // Updates to match changes in EemcTrigUtil
961 //
962 // Revision 1.12 2009/02/20 23:40:17 pibero
963 // Updates for Run 9 by Liaoyuan
964 //
965 // Revision 1.11 2009/02/04 20:01:28 rfatemi
966 // Change includes for StEmcDecoder
967 //
968 // Revision 1.10 2007/11/08 20:59:52 kocolosk
969 // subdet isTrigger returns a bool
970 // triggerDecision returns enumerator including kDoNotCare
971 //
972 // Revision 1.9 2007/10/12 20:11:33 balewski
973 // cleanup of setup path, now at inst/iucf
974 //
975 // Revision 1.8 2007/10/11 00:33:03 balewski
976 // L2algo added
977 //
978 // Revision 1.7 2007/09/24 18:08:42 kocolosk
979 // added inheritance from ABC clss StTriggerSimu
980 //
981 // Revision 1.6 2007/07/24 01:32:59 balewski
982 // added HTTP id for the endcap
983 //
984 // Revision 1.5 2007/07/23 03:00:00 balewski
985 // cleanup, bbc for M-C still not working
986 //
987 
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
Definition: EEmcDbItem.h:20
Definition: EEdsm3.h:7
StTriggerSimuDecision triggerDecision(int trigId)
like isTrigger(), but returns kDoNotCare if detector isn&#39;t a part of the given trigId ...
char tube[StEEmcNameLen]
name of PMT or MAPMT pixel
Definition: EEmcDbItem.h:21
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
Definition: StMuDst.h:389
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Collection of trigger ids as stored in MuDst.
int chan
hardware channel
Definition: EEmcDbItem.h:28