34 #include "StFcsTriggerSimMaker.h"
39 #include "StMessMgr.h"
41 #include "StarGenerator/BASE/StarPrimaryMaker.h"
42 #include "StarGenerator/EVENT/StarGenEvent.h"
44 #include "StThreeVectorF.hh"
45 #include "StEvent/StEventTypes.h"
46 #include "StEvent/StFcsHit.h"
47 #include "StFcsDbMaker/StFcsDb.h"
49 #include "RTS/include/rtsLog.h"
51 #include "StRoot/RTS/src/TRG_FCS/fcs_trg_base.h"
55 #include "StMuDSTMaker/COMMON/StMuDst.h"
56 #include "StMuDSTMaker/COMMON/StMuEvent.h"
57 #include "StMuDSTMaker/COMMON/StMuFcsCollection.h"
58 #include "StMuDSTMaker/COMMON/StMuFcsHit.h"
59 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
60 #include "StMuDSTMaker/COMMON/StMuEvent.h"
61 #include "StMuDSTMaker/COMMON/StMuFcsCollection.h"
64 enum {kMaxNS=2, kMaxDet=3, kMaxDep=24, kMaxCh=32, kMaxEcalDep=24, kMaxHcalDep=8, kMaxPresDep=4, kMaxLink2=2};
65 uint32_t fcs_trg_sim_adc[kMaxNS][kMaxDet][kMaxDep][kMaxCh] ;
66 float fcs_trg_pt_correction[kMaxNS][kMaxDet][kMaxDep][kMaxCh];
67 float fcs_trg_gain_correction[kMaxNS][kMaxDet][kMaxDep][kMaxCh];
68 uint16_t fcs_trg_pedestal[kMaxNS][kMaxDet][kMaxDep][kMaxCh] ;
70 static const int mNTRG=21;
71 static const char* ctrg[mNTRG]={
"JP2",
"JPA1",
"JPA0",
"JPBC1",
"JPBC0",
"JPDE1",
"JPDE0",
73 "DY",
"JPsi",
"DYNoEpd",
"DYAsy",
82 StFcsTriggerSimMaker::StFcsTriggerSimMaker(
const char* name):
StMaker(name) {}
84 StFcsTriggerSimMaker::~StFcsTriggerSimMaker(){}
86 int StFcsTriggerSimMaker::Init(){
87 LOG_INFO <<
"StFcsTriggerSimMaker::Init" << endm;
89 mFcsDb=
static_cast<StFcsDb*
>(GetDataSet(
"fcsDb"));
91 LOG_ERROR <<
"StFcsTriggerSimMaker::Init Failed to get StFcsDb" << endm;
95 rtsLogOutput(RTS_LOG_STDERR) ;
100 mTrgSim->run_start(0);
101 mTrgSim->fcs_trgDebug=mDebug;
104 if(mTrgSelect==201900){
105 mTrgSim->stage_version[0]=0;
106 mTrgSim->stage_version[1]=0;
107 mTrgSim->stage_version[2]=0;
108 mTrgSim->stage_version[3]=0;
109 }
else if(mTrgSelect==202201){
110 mTrgSim->stage_version[0]=0;
111 mTrgSim->stage_version[1]=1;
112 mTrgSim->stage_version[2]=1;
113 mTrgSim->stage_version[3]=1;
114 }
else if(mTrgSelect==202203){
115 mTrgSim->stage_version[0]=2;
116 mTrgSim->stage_version[1]=1;
117 mTrgSim->stage_version[2]=3;
118 mTrgSim->stage_version[3]=3;
119 }
else if(mTrgSelect==202204){
120 mTrgSim->stage_version[0]=2;
121 mTrgSim->stage_version[1]=1;
122 mTrgSim->stage_version[2]=4;
123 mTrgSim->stage_version[3]=3;
124 }
else if(mTrgSelect==202205){
125 mTrgSim->stage_version[0]=2;
126 mTrgSim->stage_version[1]=1;
127 mTrgSim->stage_version[2]=5;
128 mTrgSim->stage_version[3]=3;
129 }
else if(mTrgSelect==202206){
130 mTrgSim->stage_version[0]=2;
131 mTrgSim->stage_version[1]=1;
132 mTrgSim->stage_version[2]=6;
133 mTrgSim->stage_version[3]=3;
134 }
else if(mTrgSelect==202207){
135 mTrgSim->stage_version[0]=2;
136 mTrgSim->stage_version[1]=1;
137 mTrgSim->stage_version[2]=7;
138 mTrgSim->stage_version[3]=7;
139 }
else if(mTrgSelect==202209){
140 mTrgSim->stage_version[0]=3;
141 mTrgSim->stage_version[1]=1;
142 mTrgSim->stage_version[2]=7;
143 mTrgSim->stage_version[3]=7;
149 }
else if(mThresholdDb){
160 printf(
"Reading PresMask from %s\n",mPresMask);
161 FILE* F=fopen(mPresMask,
"r");
163 printf(
"Cannot open %s\n",mPresMask);
167 while(fgets(line,
sizeof(line),F)){
172 sscanf(line,
"%d %d %x %x %x %x %x %x",&r,&c,&m[0],&m[1],&m[2],&m[3],&m[4],&m[5]);
173 printf(
"%2d %1d %08x %08x %08x %08x %08x %08x\n",r,c,m[0],m[1],m[2],m[3],m[4],m[5]);
174 for(
int i=0; i<6; i++) mTrgSim->PRES_MASK[r-1][c-1][i]=m[i];
176 mTrgSim->fcs_readPresMaskFromText=1;
180 memset(NTRG,0,
sizeof(NTRG));
184 int StFcsTriggerSimMaker::InitRun(
int runNumber){
185 LOG_INFO <<
"StFcsTriggerSimMaker::InitRun" << endm;
194 mQaTreeFile=
new TFile(mQaTreeFilename,
"RECREATE");
195 mTree =
new TTree(
"trgsim",
"trigger sim QA");
196 mTree->Branch(
"flt",&mFlt,
"flt/I");
197 mTree->Branch(
"trg",&mTrg,
"trg/I");
200 mQaHistFile=
new TFile(mQaHistFilename,
"RECREATE");
201 mTrgRate =
new TH1F(
"FcsTrgRate",
"FcsTrgRate",mNTRG+1,0,mNTRG+1);
208 mFile = fopen(mFilename,
"w");
209 gainfile=fopen(
"fcs_et_gain.txt",
"w");
210 gainfile2=fopen(
"fcs_et_gain2.txt",
"w");
214 for(
int det=0; det<=kFcsNDet; det++){
215 int nid=mFcsDb->
maxId(det);
216 for(
int id=0;
id<nid;
id++){
217 int ehp,ns,crt,sub,dep,ch;
220 fcs_trg_pt_correction[ns][ehp][dep][ch] = mFcsDb->getEtGain(det,
id,mEtFactor);
221 fcs_trg_gain_correction[ns][ehp][dep][ch] = mFcsDb->
getGainOnline(det,
id);
223 fcs_trg_pt_correction[ns][ehp][dep][ch] = 1.0;
224 fcs_trg_gain_correction[ns][ehp][dep][ch] = 1.0;
226 fcs_trg_pedestal[ns][ehp][dep][ch] = 0;
228 mTrgSim->p_g[ns][ehp][dep][ch].ped = fcs_trg_pedestal[ns][ehp][dep][ch];
230 if(mOverwriteGain==1){
231 float ggg = fcs_trg_pt_correction[ns][ehp][dep][ch];
233 float gg = ggg * fcs_trg_gain_correction[ns][ehp][dep][ch];
234 int g = (uint32_t)(gg*256.0+0.5) ;
235 mTrgSim->p_g[ns][ehp][dep][ch].gain = g;
246 fprintf(gainfile,
"%2d %2d %2d %2d %8.3f\n",ns,ehp,dep,ch,
247 fcs_trg_pt_correction[ns][ehp][dep][ch]);
249 fprintf(gainfile2,
"%2d %2d %2d %2d %8.3f\n",ns,ehp,dep,ch,
250 (fcs_trg_pt_correction[ns][ehp][dep][ch]-1.0)/2.0 + 1.0);
253 if(gainfile) fclose(gainfile);
254 if(gainfile2) fclose(gainfile2);
261 printf(
"Closing %s\n",mFilename);
265 printf(
"Closing %s\n",mQaTreeFilename);
267 mQaTreeFile->Close();
270 printf(
"Closing %s\n",mQaHistFilename);
272 mQaHistFile->Close();
275 int tot = NTRG[mNTRG];
276 LOG_INFO <<
"Triggers counts/"<<tot<<
" (rate at 5MHz BBC)"<<endm;
277 for(
int i=0; i<mNTRG; i++)
278 LOG_INFO << Form(
"%8s %9d (%12.2f)",ctrg[i],NTRG[i],
double(NTRG[i])/tot*5.0e6)<<endm;
285 event = (
StEvent*)GetInputDS(
"StEvent");
287 LOG_INFO <<
"StFcsTriggerSimMaker::Make did not find StEvent"<<endm;}
289 mFcsColl =
event->fcsCollection();
290 if(!mFcsColl){LOG_INFO <<
"StFcsTriggerSimMaker::Make did not find StEvent->StFcsCollection"<<endm;}
294 if((!event)||(!mFcsColl)){
295 LOG_INFO<<
"No StEvent info available for StFcsTriggerSimMaker. "<< endm;
298 if(muevent && mMuFcsColl){
299 LOG_INFO <<
"Proceeding with StMuDst info to be used with StfcsTriggerSimMaker."<< endm;
301 LOG_ERROR <<
"StFcsTriggerSimMaker::Make did not find StEvent and MuEvent." << endm;
306 mTrgSim->start_event();
309 static uint16_t
data[8];
310 memset(data,0,
sizeof(data)) ;
311 memset(fcs_trg_sim_adc,0,
sizeof(fcs_trg_sim_adc));
313 for(
int det=0; det<=kFcsNDet; det++){
318 if((event)&&(mFcsColl)){
319 StSPtrVecFcsHit& hits = mFcsColl->hits(det);
321 int nh = mFcsColl->numberOfHits(det);
323 for(
int i=0; i<nh; i++){
325 unsigned short ch = hit->channel();
327 if(ehp<0 || ch>=32)
continue;
328 feedADC(hit, ns, ehp, data);
332 }
else if((muevent)&&(mMuFcsColl)){
334 int nh = mMuFcsColl->numberOfHits(det);
335 int det_hit_index = mMuFcsColl->indexOfFirstHit(det);
337 for(
int i=0; i<nh; i++){
339 int hit_index = i + det_hit_index;
341 unsigned short ch = hit->channel();
343 if(ehp<0 || ch>=32)
continue;
344 feedADC(hit, ns, ehp, data);
349 if(mFile) fprintf(mFile,
"%2d %2d %2d %2d %5d\n",-1,0,0,0,0);
350 LOG_INFO << Form(
"StFcsTriggerSimMaker feeded %d hits",n) << endm;;
354 uint32_t dsm_out = mTrgSim->end_event();
355 LOG_INFO << Form(
"AAA dsmout=%08x",dsm_out)<<endm;
367 if(mQaTreeFile) mTree->Fill();
370 LOG_INFO << Form(
"Output to TCU = 0x%08x Filter=0x%08x",mTcu,mFlt)<<endm;
375 memset(trg,0,
sizeof(trg));
376 if((dsm_out >> 6) & 0x1) {trg[ 0]=1; mTrg+=1<<0;}
377 if((dsm_out >> 7) & 0x1) {trg[ 1]=1; mTrg+=1<<1;}
378 if((dsm_out >>10) & 0x1) {trg[ 2]=1; mTrg+=1<<2;}
379 if((dsm_out >> 8) & 0x1) {trg[ 3]=1; mTrg+=1<<3;}
380 if((dsm_out >>11) & 0x1) {trg[ 4]=1; mTrg+=1<<4;}
381 if((dsm_out >> 9) & 0x1) {trg[ 5]=1; mTrg+=1<<5;}
382 if((dsm_out >>12) & 0x1) {trg[ 6]=1; mTrg+=1<<6;}
383 if((dsm_out >>13) & 0x1) {trg[ 7]=1; mTrg+=1<<7;}
384 if((dsm_out >>14) & 0x1) {trg[ 8]=1; mTrg+=1<<8;}
385 if( ((dsm_out >>18) & 0x1) &&
386 ((dsm_out >>26) & 0x1) ) {trg[ 9]=1; mTrg+=1<<9;}
387 if( ((dsm_out >>17) & 0x1) &&
388 ((dsm_out >>25) & 0x1) ) {trg[10]=1; mTrg+=1<<10;}
389 if( ((dsm_out >>19) & 0x1) &&
390 ((dsm_out >>27) & 0x1) ) {trg[11]=1; mTrg+=1<<11;}
391 if((dsm_out >>15) & 0x1) {trg[12]=1; mTrg+=1<<12;}
392 if((dsm_out >> 2) & 0x1) {trg[13]=1; mTrg+=1<<13;}
393 if((dsm_out >> 1) & 0x1) {trg[14]=1; mTrg+=1<<14;}
394 if((dsm_out >> 0) & 0x1) {trg[15]=1; mTrg+=1<<15;}
395 if((dsm_out >> 5) & 0x1) {trg[16]=1; mTrg+=1<<16;}
396 if((dsm_out >> 4) & 0x1) {trg[17]=1; mTrg+=1<<17;}
397 if((dsm_out >> 3) & 0x1) {trg[18]=1; mTrg+=1<<18;}
398 if( ((dsm_out >>18) & 0x1) ||
399 ((dsm_out >>26) & 0x1) ) {trg[19]=1; mTrg+=1<<19;}
400 if( ((dsm_out >>19) & 0x1) ||
401 ((dsm_out >>27) & 0x1) ) {trg[20]=1; mTrg+=1<<20;}
403 if(mTrgRate) mTrgRate->Fill(mNTRG);
405 for(
int i=0; i<mNTRG; i++){
407 if(mTrgRate) mTrgRate->Fill(i);
412 LOG_INFO <<
"Triggers = ";
413 for(
int i=0; i<mNTRG; i++){
if(trg[i]) LOG_INFO << ctrg[i] <<
" ";}
420 int dta[],
int dsmout,
int sim[],
int simdsmout,
int iev){
421 unsigned short emu[8];
422 mTrgSim->stage_2(ecal,hcal,pres,geo,output,&dsm);
423 for(
int i=0; i<8; i++) emu[i] = output[0].d[i] + (output[1].d[i] << 8);
424 printf(
"Event#=%3d emuout = ",iev);
for(
int i=0; i<8; i++) {printf(
"%04x ",emu[i]);}
425 printf(
"TCU=%04x\n",dsm);
426 printf(
"Event#=%3d dtaout = ",iev);
for(
int i=0; i<8; i++) {printf(
"%04x ",dta[i]);}
427 printf(
"TCU=%04x\n",dsmout);
428 printf(
"Event#=%3d simout = ",iev);
for(
int i=0; i<8; i++) {printf(
"%04x ",sim[i]);}
429 printf(
"TCU=%04x\n",simdsmout);
430 const char* s2bit[3][16]={{
"EM0 ",
"EM1 ",
"EM2 ",
"EM3 ",
"ELE0",
"ELE1",
"ELE2",
"PRS ",
431 "HAD0",
"HAD1",
"HAD2",
"xxxx",
"EHT ",
"HHT ",
"ETOT",
"HTOT"},
432 {
"JPA2",
"JPB2",
"JPC2",
"JPD2",
"JPE2",
"xxxx",
"xxxx",
"xxxx",
433 "JPA1",
"JPB1",
"JPC1",
"JPD1",
"JPE1",
"xxxx",
"xxxx",
"xxxx"},
434 {
"JPA0",
"JPB0",
"JPC0",
"JPD0",
"JPE0",
"xxxx",
"xxxx",
"xxxx",
435 "JPAd",
"JPBd",
"JPCd",
"JPDd",
"JPEd",
"xxxx",
"xxxx",
"xxxx"}};
436 for(
int i=0; i<3; i++){
437 for(
int j=0; j<16; j++){
438 if( ((dta[i]>>j)&1) != ((sim[i]>>j)&1) ||
439 ((sim[i]>>j)&1) != ((emu[i]>>j)&1) ||
440 ((emu[i]>>j)&1) != ((dta[i]>>j)&1) ){
441 printf(
"Event#=%3d STG2to3 ns=%1d i=%d j=%2d %s dat=%x sim=%x emu=%x",
442 iev,geo.ns,i,j,s2bit[i][j],(dta[i]>>j)&1,(sim[i]>>j)&1,(emu[i]>>j)&1);
444 int maxr=0, maxc=0, max=0;
445 for(
int r=0; r<15; r++){
446 for(
int c=0; c<9; c++){
447 if(max < mTrgSim->esum[geo.ns][r][c]) {maxr=r; maxc=c; max=mTrgSim->esum[geo.ns][r][c];}
450 printf(
" EsumMax=%4d ratio=%4.3f",
451 mTrgSim->esum[geo.ns][maxr][maxc],
452 mTrgSim->ratiomax[geo.ns][maxr][maxc]);
453 if(j>=4) printf(
" Epd=%1d",mTrgSim->epdcoin[geo.ns][maxr][maxc]);
454 if(j==0) printf(
" EMTHR0=%4d",mTrgSim->EMTHR0);
455 if(j==1) printf(
" EMTHR1=%4d",mTrgSim->EMTHR1);
456 if(j==2) printf(
" EMTHR2=%4d",mTrgSim->EMTHR2);
457 if(j==3) printf(
" ELETHR2=%4d",mTrgSim->ELETHR2);
458 if(j==4) printf(
" ELETHR0=%4d",mTrgSim->ELETHR0);
459 if(j==5) printf(
" ELETHR1=%4d",mTrgSim->ELETHR1);
460 if(j==6) printf(
" ELETHR2=%4d",mTrgSim->ELETHR2);
462 if(i==1 && j== 0){ printf(
" JPA=%4d thr2=%4d",mTrgSim->jet[geo.ns][0],mTrgSim->JPATHR2);}
463 if(i==1 && j== 1){ printf(
" JPB=%4d thr2=%4d",mTrgSim->jet[geo.ns][1],mTrgSim->JPBCTHR2);}
464 if(i==1 && j== 2){ printf(
" JPC=%4d thr2=%4d",mTrgSim->jet[geo.ns][2],mTrgSim->JPBCTHR2);}
465 if(i==1 && j== 3){ printf(
" JPD=%4d thr2=%4d",mTrgSim->jet[geo.ns][3],mTrgSim->JPDETHR2);}
466 if(i==1 && j== 4){ printf(
" JPE=%4d thr2=%4d",mTrgSim->jet[geo.ns][4],mTrgSim->JPDETHR2);}
467 if(i==1 && j== 8){ printf(
" JPA=%4d thr1=%4d",mTrgSim->jet[geo.ns][0],mTrgSim->JPATHR1);}
468 if(i==1 && j== 9){ printf(
" JPB=%4d thr1=%4d",mTrgSim->jet[geo.ns][1],mTrgSim->JPBCTHR1);}
469 if(i==1 && j==10){ printf(
" JPC=%4d thr1=%4d",mTrgSim->jet[geo.ns][2],mTrgSim->JPBCTHR1);}
470 if(i==1 && j==11){ printf(
" JPD=%4d thr1=%4d",mTrgSim->jet[geo.ns][3],mTrgSim->JPDETHR1);}
471 if(i==1 && j==12){ printf(
" JPE=%4d thr1=%4d",mTrgSim->jet[geo.ns][4],mTrgSim->JPDETHR1);}
472 if(i==2 && j== 0){ printf(
" JPA=%4d thr0=%4d",mTrgSim->jet[geo.ns][0],mTrgSim->JPATHR0);}
473 if(i==2 && j== 1){ printf(
" JPB=%4d thr0=%4d",mTrgSim->jet[geo.ns][1],mTrgSim->JPBCTHR0);}
474 if(i==2 && j== 2){ printf(
" JPC=%4d thr0=%4d",mTrgSim->jet[geo.ns][2],mTrgSim->JPBCTHR0);}
475 if(i==2 && j== 3){ printf(
" JPD=%4d thr0=%4d",mTrgSim->jet[geo.ns][3],mTrgSim->JPDETHR0);}
476 if(i==2 && j== 4){ printf(
" JPE=%4d thr0=%4d",mTrgSim->jet[geo.ns][4],mTrgSim->JPDETHR0);}
477 if(i==2 && j== 8){ printf(
" JPA=%4d thrD=%4d",mTrgSim->jet[geo.ns][0],-1);}
478 if(i==2 && j== 9){ printf(
" JPB=%4d thrD=%4d",mTrgSim->jet[geo.ns][1],mTrgSim->JPBCTHRD);}
479 if(i==2 && j==10){ printf(
" JPC=%4d thrD=%4d",mTrgSim->jet[geo.ns][2],mTrgSim->JPBCTHRD);}
480 if(i==2 && j==11){ printf(
" JPD=%4d thrD=%4d",mTrgSim->jet[geo.ns][3],mTrgSim->JPDETHRD);}
481 if(i==2 && j==12){ printf(
" JPE=%4d thrD=%4d",mTrgSim->jet[geo.ns][4],mTrgSim->JPDETHRD);}
488 void StFcsTriggerSimMaker::print4B4(){
490 FILE* f1=fopen(
"EH4by4.txt",
"w");
491 FILE* f2=fopen(
"EH4by4dist.txt",
"w");
492 FILE* f3=fopen(
"EH4by4map.txt",
"w");
493 FILE* f4=fopen(
"EH2by2dist.txt",
"w");
494 FILE* f5=fopen(
"EH2by2map.txt",
"w");
495 FILE* f6=fopen(
"EH2by2map2.txt",
"w");
501 enum {EX2B2=10,EY2B2=16,HX2B2=6,HY2B2=10};
502 enum {EXOFF=1,EYOFF=1,HXOFF=0,HYOFF=0};
512 float esmx=mFcsDb->getShowerMaxZ(1);
513 float hsmx=mFcsDb->getShowerMaxZ(3);
514 float r1 = sqrt(eoff.x()*eoff.x()+eoff.z()*eoff.z());
515 float r2 = r1 + esmx;
516 float r3 = sqrt(hoff.x()*hoff.x()+hoff.z()*hoff.z());
517 float r4 = r3 + hsmx;
519 fprintf(f1,
"Distannce from IP to EcalSmax=%8.3f HcalSMax=%8.3f Ratio=%6.3f\n",r2,r4,sf);
521 fprintf(f1,
"\nHcal 4x4\n");
522 fprintf(f1,
" C R XY[cell] XYZ[cm]\n");
523 for(
int ns=1; ns<2; ns++){
524 for(
int j=0; j<HY2B2-1; j++){
525 float y=j*2 + HYOFF + 2;
526 for(
int i=0; i<HX2B2-1; i++){
527 float x=i*2 + HXOFF + 2;
529 fprintf(f1,
"H %2d %2d %4.1f %4.1f %8.2f %8.2f %8.2f\n",
530 i,j,x,y,hxyz[ns][i][j].x(),hxyz[ns][i][j].y(),hxyz[ns][i][j].z());
535 fprintf(f1,
"\nHcal 2x2\n");
536 fprintf(f1,
" C R XY[cell] XYZ[cm]\n");
537 for(
int ns=1; ns<2; ns++){
538 for(
int j=0; j<HY2B2; j++){
539 float y=j*2 + HYOFF + 1;
540 for(
int i=0; i<HX2B2; i++){
541 float x=i*2 + HXOFF + 1;
543 fprintf(f1,
"H %2d %2d %4.1f %4.1f %8.2f %8.2f %8.2f\n",
544 i,j,x,y,Hxyz[ns][i][j].x(),Hxyz[ns][i][j].y(),Hxyz[ns][i][j].z());
549 fprintf(f1,
"\nEcal 4x4\n");
550 fprintf(f1,
" C R XY[cell] XYZ[cm] | XYZ at HCAL | C R distance XYZ of closest Hcal 4x4\n");
552 fprintf(f3,
"static const int EtoHmap[%d][%d][2] = {\n",EY2B2-1,EX2B2-1);
553 fprintf(f5,
"static const int EtoH2map[%d][%d][2] = {\n",EY2B2-1,EX2B2-1);
554 fprintf(f6,
"static const int EtoH3map[%d][%d][4] = {\n",EY2B2-1,EX2B2-1);
555 for(
int ns=1; ns<2; ns++){
556 for(
int j=0; j<EY2B2-1; j++){
557 float y=j*2 + EYOFF + 2;
559 for(
int i=0; i<EX2B2-1; i++){
560 float x=i*2 + EXOFF + 2;
562 sxyz[ns][i][j] = sf * exyz[ns][i][j];
566 for(
int ii=0; ii<HX2B2-1; ii++){
567 for(
int jj=0; jj<HY2B2-1; jj++){
569 float d = diff.mag();
579 fprintf(f1,
"E %2d %2d %4.1f %4.1f %8.2f %8.2f %8.2f | %8.2f %8.2f %8.2f | %2d %2d %6.2f %8.2f %8.2f %8.2f\n",
581 exyz[ns][i][j].x(),exyz[ns][i][j].y(),exyz[ns][i][j].z(),
582 sxyz[ns][i][j].x(),sxyz[ns][i][j].y(),sxyz[ns][i][j].z(),
584 hxyz[ns][k][l].x(),hxyz[ns][k][l].y(),hxyz[ns][k][l].z());
585 fprintf(f2,
"%6.2f ",dmin);
586 if(i==EX2B2-2) fprintf(f2,
"\n");
587 fprintf(f3,
"{%2d,%2d}",l,k);
588 if(i<EX2B2-2) fprintf(f3,
",");
589 if(i==EX2B2-2) fprintf(f3,
"}");
594 for(
int ii=0; ii<HX2B2; ii++){
595 for(
int jj=0; jj<HY2B2; jj++){
597 float d = diff.mag();
607 fprintf(f1,
"E %2d %2d %4.1f %4.1f %8.2f %8.2f %8.2f | %8.2f %8.2f %8.2f | %2d %2d %6.2f %8.2f %8.2f %8.2f\n",
609 exyz[ns][i][j].x(),exyz[ns][i][j].y(),exyz[ns][i][j].z(),
610 sxyz[ns][i][j].x(),sxyz[ns][i][j].y(),sxyz[ns][i][j].z(),
612 Hxyz[ns][kk][ll].x(),Hxyz[ns][kk][ll].y(),Hxyz[ns][kk][ll].z());
613 fprintf(f4,
"%6.2f ",dmin2);
614 if(i==EX2B2-2) fprintf(f4,
"\n");
616 fprintf(f5,
"{%2d,%2d}",ll,kk);
617 if(i<EX2B2-2) fprintf(f5,
",");
618 if(i==EX2B2-2) fprintf(f5,
"}");
620 int i1=kk-1, i2=kk, j1=ll-1, j2=ll;
621 int r1=-1, r2=-1, r3=-1, r4=-1;
622 if(i1>=0 && i1<HX2B2-1 && j1>=0 && j1<HY2B2-1) r1=i1+j1*(HX2B2-1);
623 if(i2>=0 && i2<HX2B2-1 && j1>=0 && j1<HY2B2-1) r2=i2+j1*(HX2B2-1);
624 if(i1>=0 && i1<HX2B2-1 && j2>=0 && j2<HY2B2-1) r3=i1+j2*(HX2B2-1);
625 if(i2>=0 && i2<HX2B2-1 && j2>=0 && j1<HY2B2-1) r4=i2+j2*(HX2B2-1);
626 fprintf(f6,
"{%2d,%2d,%2d,%2d}",r1,r2,r3,r4);
627 if(i<EX2B2-2) fprintf(f6,
",");
628 if(i==EX2B2-2) fprintf(f6,
"}");
630 if(j<EY2B2-2) fprintf(f3,
",\n");
631 if(j==EY2B2-2) fprintf(f3,
"\n");
632 if(j<EY2B2-2) fprintf(f5,
",\n");
633 if(j==EY2B2-2) fprintf(f5,
"\n");
634 if(j<EY2B2-2) fprintf(f6,
",\n");
635 if(j==EY2B2-2) fprintf(f6,
"\n");
651 void StFcsTriggerSimMaker::printJP(){
653 FILE* f1=fopen(
"EHJP.txt",
"w");
654 FILE* f2=fopen(
"EHJPdist.txt",
"w");
656 enum {EXOFF=1,EYOFF=1,HXOFF=0,HYOFF=2};
662 float esmx=mFcsDb->getShowerMaxZ(1);
663 float hsmx=mFcsDb->getShowerMaxZ(3);
664 float r1 = sqrt(eoff.x()*eoff.x()+eoff.z()*eoff.z());
665 float r2 = r1 + esmx;
666 float r3 = sqrt(hoff.x()*hoff.x()+hoff.z()*hoff.z());
667 float r4 = r3 + hsmx;
669 fprintf(f1,
"Distannce from IP to EcalSmax=%8.3f HcalSMax=%8.3f Ratio=%6.3f\n",r2,r4,sf);
670 fprintf(f1,
"\nHcal 8x8\n");
671 fprintf(f1,
" C R XY[cell] XYZ[cm]\n");
672 for(
int ns=1; ns<2; ns++){
673 for(
int j=0; j<5; j++){
674 float y=j*2 + HYOFF + 4;
675 for(
int i=0; i<3; i++){
676 float x=i*2 + HXOFF + 4;
678 fprintf(f1,
"H %2d %2d %4.1f %4.1f %8.2f %8.2f %8.2f\n",
679 i,j,x,y,hxyz[ns][i][j].x(),hxyz[ns][i][j].y(),hxyz[ns][i][j].z());
683 fprintf(f1,
"\nEcal 12x16\n");
684 fprintf(f1,
" C R XY[cell] XYZ[cm] | XYZ at HCAL | distance XYZ of Hcal 8x8\n");
685 for(
int ns=1; ns<2; ns++){
686 for(
int j=0; j<5; j++){
687 float y=j*4 + EYOFF + 8;
688 for(
int i=0; i<3; i++){
689 float x=i*4 + EXOFF + 6;
691 sxyz[ns][i][j] = sf * exyz[ns][i][j];
693 float d = diff.mag();
694 fprintf(f1,
"E %2d %2d %4.1f %4.1f %8.2f %8.2f %8.2f | %8.2f %8.2f %8.2f | %6.2f %8.2f %8.2f %8.2f\n",
696 exyz[ns][i][j].x(),exyz[ns][i][j].y(),exyz[ns][i][j].z(),
697 sxyz[ns][i][j].x(),sxyz[ns][i][j].y(),sxyz[ns][i][j].z(),
699 hxyz[ns][i][j].x(),hxyz[ns][i][j].y(),hxyz[ns][i][j].z());
700 fprintf(f2,
"%6.2f ",d);
701 if(i==2) fprintf(f2,
"\n");
710 void StFcsTriggerSimMaker::readThresholdFile(){
711 LOG_INFO << Form(
"Reading Thresholds from %s",mThresholdFile)<<endm;
712 FILE* F=fopen(mThresholdFile,
"r");
714 LOG_ERROR << Form(
"Could not open %s",mThresholdFile)<<endm;
717 char f[10],name[100];
719 while(fscanf(F,
"%s %d %d %s %d",f, &i, &
id, name, &v) != EOF){
720 if(f[0] ==
'#')
continue;
722 printf(
"Reading Threshold %s %d\n",trg.Data(),v);
723 if (trg==
"FCS_PHTTHR") mTrgSim->PHTTHR=v;
724 else if(trg==
"FCS_EM-HERATIO-THR") mTrgSim->EM_HERATIO_THR=v;
725 else if(trg==
"FCS_HAD-HERATIO-THR") mTrgSim->HAD_HERATIO_THR=v;
726 else if(trg==
"FCS_EMTHR2") mTrgSim->EMTHR2=v;
727 else if(trg==
"FCS_EMTHR1") mTrgSim->EMTHR1=v;
728 else if(trg==
"FCS_EMTHR0") mTrgSim->EMTHR0=v;
729 else if(trg==
"FCS_ELETHR2") mTrgSim->ELETHR2=v;
730 else if(trg==
"FCS_ELETHR1") mTrgSim->ELETHR1=v;
731 else if(trg==
"FCS_ELETHR0") mTrgSim->ELETHR0=v;
732 else if(trg==
"FCS_HADTHR2") mTrgSim->HADTHR2=v;
733 else if(trg==
"FCS_HADTHR1") mTrgSim->HADTHR1=v;
734 else if(trg==
"FCS_HADTHR0") mTrgSim->HADTHR0=v;
735 else if(trg==
"FCS_JPATHR2") mTrgSim->JPATHR2=v;
736 else if(trg==
"FCS_JPATHR1") mTrgSim->JPATHR2=v;
737 else if(trg==
"FCS_JPATHR0") mTrgSim->JPATHR0=v;
738 else if(trg==
"FCS_JPBCTHR2") mTrgSim->JPBCTHR2=v;
739 else if(trg==
"FCS_JPBCTHR1") mTrgSim->JPBCTHR1=v;
740 else if(trg==
"FCS_JPBCTHR0") mTrgSim->JPBCTHR0=v;
741 else if(trg==
"FCS_JPBCTHRD") mTrgSim->JPBCTHRD=v;
742 else if(trg==
"FCS_JPDETHR2") mTrgSim->JPDETHR2=v;
743 else if(trg==
"FCS_JPDETHR1") mTrgSim->JPDETHR1=v;
744 else if(trg==
"FCS_JPDETHR0") mTrgSim->JPDETHR0=v;
745 else if(trg==
"FCS_JPDETHRD") mTrgSim->JPDETHRD=v;
746 else if(trg==
"FCS_EHTTHR") mTrgSim->EHTTHR=v;
747 else if(trg==
"FCS_HHTTHR") mTrgSim->HHTTHR=v;
748 else if(trg==
"FCS_ETOTTHR") mTrgSim->ETOTTHR=v;
749 else if(trg==
"FCS_HTOTTHR") mTrgSim->HTOTTHR=v;
751 printf(
"No Threshold called %s %d\n",trg.Data(),v);
758 void StFcsTriggerSimMaker::readThresholdDb(){
762 template<
typename T>
void StFcsTriggerSimMaker::feedADC(T*
hit,
int ns,
int ehp, uint16_t data_array[]){
764 unsigned short dep = hit->dep();
765 unsigned short ch = hit->channel();
768 fcs_trg_sim_adc[ns][ehp][dep][ch] = hit->adc(0);
770 int ntb=hit->nTimeBin();
771 for(
int t=0; t<ntb; t++){
772 int tb = hit->timebin(t);
773 if(tb>=mTrgTimebin-3 && tb<=mTrgTimebin+4){
774 data_array[tb-mTrgTimebin+3] = hit->adc(t);
778 mTrgSim->fill_event(ehp,ns,dep,ch,data_array,8) ;
780 data_array[1] = hit->adc(0)-1;
782 mTrgSim->fill_event(ehp,ns,dep,ch,data_array,8) ;
784 if(mFile) fprintf(mFile,
"%2d %2d %2d %2d %5d\n",ns,ehp,dep,ch,hit->adc(0));
788 void StFcsTriggerSimMaker::readTrgId(){
792 LOG_INFO<<
"Reading "<<mTrgIdFile<<endm;
793 FILE* fp=fopen(mTrgIdFile,
"r");
794 if(!fp) {LOG_WARN <<
"Cannot open "<<mTrgIdFile<<endm;
return;}
796 fscanf(fp,
"%d %s",&i,trgn);
798 LOG_INFO <<
"TRGID "<<i<<
"="<<mTrgIdName[i].Data()<<endm;
static StMuFcsCollection * muFcsCollection()
returns pointer to current StMuFcsCollection
float getGainOnline(int det, int id) const
get the pres valley position for cut
int northSouth(int det) const
Ecal=0, Hcal=1, Pres=2.
StThreeVectorD getDetectorOffset(int det, double zdepth=-1) const
Utility functions related to DetectorPosition.
StThreeVectorD getStarXYZfromColumnRow(int det, float col, float row, float FcsZ=-1.0) const
get the STAR frame cooridnates from other way
int ecalHcalPres(int det) const
Ecal North=0, Ecal South=1, Hcal North=2, Hcal South=3, Pres=4/5.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Base class for event records.
StarGenEvent * event()
Return a pointer to the event.
Main steering class for event generation.
int maxId(int det) const
number of column
UInt_t GetFilterResult()
Returns the filter result.
void getDepfromId(int detectorId, int id, int &ehp, int &ns, int &crt, int &slt, int &dep, int &ch) const
print ET gain