From 878013be5f6810aa40bba356c3842fbfaa971bdd Mon Sep 17 00:00:00 2001 From: akioogawa <85249930+akioogawa@users.noreply.github.com> Date: Wed, 10 Nov 2021 15:11:58 -0500 Subject: [PATCH] Updates from Tonko on StRoot/RTS/src/DAQ_FCS and TRG_FCS (#179) * Updates from Tonko on StRoot/RTS/src/DAQ_FCS and TRG_FCS Adding run22 trigger algo in StRoot/RTS/src/TRG_FCS StFcsDb updates on flexible ETGain, fixing reading Gains from text, macro for gain DB StFcsWaveformFitMaker adding stage0 peak finder QA StFcsTriggerSimMaker adding run22 TCU emulator, reading thresholds from text, ET/E gain match selection * Adding forgotton Stage2 algo codes * Adding EPD for getName() Adding s2_to_dsm return for runStage2() --- StRoot/RTS/src/TRG_FCS/Makefile | 9 +- StRoot/RTS/src/TRG_FCS/fcs_trg_base.cxx | 188 ++++++--- StRoot/RTS/src/TRG_FCS/fcs_trg_base.h | 41 +- StRoot/RTS/src/TRG_FCS/stage_0_202109.cxx | 94 +++++ StRoot/RTS/src/TRG_FCS/stage_1_202201.cxx | 4 +- StRoot/RTS/src/TRG_FCS/stage_2_202203.cxx | 13 +- StRoot/RTS/src/TRG_FCS/stage_2_202207.cxx | 371 ++++++++++++++++++ StRoot/RTS/src/TRG_FCS/stage_2_JP5_202206.cxx | 362 +++++++++++++++++ .../src/TRG_FCS/stage_2_JP6Carl_202205.cxx | 340 ++++++++++++++++ StRoot/RTS/src/TRG_FCS/stage_2_JP6_202204.cxx | 365 +++++++++++++++++ StRoot/RTS/src/TRG_FCS/stage_3_202203.cxx | 3 +- StRoot/RTS/src/TRG_FCS/stage_3_202207.cxx | 60 +++ StRoot/StFcsDbMaker/StFcsDb.cxx | 131 ++++--- StRoot/StFcsDbMaker/StFcsDb.h | 22 +- StRoot/StFcsDbMaker/macro/fcsGain_db.C | 244 ++++++++++++ .../macro/mergerate.pl | 24 ++ StRoot/StFcsFastSimulatorMaker/macro/rate.C | 75 ++++ .../StFcsFastSimulatorMaker/macro/runSimBfc.C | 28 +- .../StFcsFastSimulatorMaker/macro/runpythia | 23 +- .../macro/stage_params.txt | 27 ++ .../macro/submitpythia.pl | 26 +- .../StFcsFastSimulatorMaker/macro/thresh.pl | 71 ++++ .../StFcsWaveformFitMaker.cxx | 62 ++- .../StFcsWaveformFitMaker.h | 5 + .../StFcsTriggerSimMaker.cxx | 258 ++++++++---- .../StFcsTriggerSimMaker.h | 27 +- 26 files changed, 2630 insertions(+), 243 deletions(-) create mode 100644 StRoot/RTS/src/TRG_FCS/stage_0_202109.cxx create mode 100644 StRoot/RTS/src/TRG_FCS/stage_2_202207.cxx create mode 100644 StRoot/RTS/src/TRG_FCS/stage_2_JP5_202206.cxx create mode 100644 StRoot/RTS/src/TRG_FCS/stage_2_JP6Carl_202205.cxx create mode 100644 StRoot/RTS/src/TRG_FCS/stage_2_JP6_202204.cxx create mode 100644 StRoot/RTS/src/TRG_FCS/stage_3_202207.cxx create mode 100644 StRoot/StFcsDbMaker/macro/fcsGain_db.C create mode 100755 StRoot/StFcsFastSimulatorMaker/macro/mergerate.pl create mode 100644 StRoot/StFcsFastSimulatorMaker/macro/rate.C create mode 100644 StRoot/StFcsFastSimulatorMaker/macro/stage_params.txt create mode 100755 StRoot/StFcsFastSimulatorMaker/macro/thresh.pl diff --git a/StRoot/RTS/src/TRG_FCS/Makefile b/StRoot/RTS/src/TRG_FCS/Makefile index fb910536b14..ba8f6afa1d0 100644 --- a/StRoot/RTS/src/TRG_FCS/Makefile +++ b/StRoot/RTS/src/TRG_FCS/Makefile @@ -42,7 +42,13 @@ fcs_trg_lib.a : fcs_trg_base.o \ stage_2_TAMU_202202.o \ stage_0_202103.o \ stage_3_202203.o \ - stage_2_202203.o + stage_2_202203.o \ + stage_0_202109.o \ + stage_2_JP6Carl_202205.o \ + stage_2_JP5_202206.o \ + stage_2_JP6_202204.o \ + stage_2_202207.o \ + stage_3_202207.o $(RTS_AR) # DO NOT DELETE @@ -53,6 +59,7 @@ fcs_trg_base.o: fcs_trg_base.h stage_0_201900.o: fcs_trg_base.h stage_0_202101.o: fcs_trg_base.h stage_0_202103.o: fcs_trg_base.h +stage_0_202109.o: fcs_trg_base.h stage_1_201900.o: fcs_trg_base.h stage_1_202201.o: fcs_trg_base.h stage_2_201900.o: fcs_trg_base.h diff --git a/StRoot/RTS/src/TRG_FCS/fcs_trg_base.cxx b/StRoot/RTS/src/TRG_FCS/fcs_trg_base.cxx index 1cdeb1cab37..d41927ae09c 100644 --- a/StRoot/RTS/src/TRG_FCS/fcs_trg_base.cxx +++ b/StRoot/RTS/src/TRG_FCS/fcs_trg_base.cxx @@ -32,14 +32,30 @@ u_int fcs_trg_base::PRES_MASK[15][9][6]; u_short fcs_trg_base::EM_HERATIO_THR ; u_short fcs_trg_base::HAD_HERATIO_THR ; +u_short fcs_trg_base::EMTHR0 ; u_short fcs_trg_base::EMTHR1 ; u_short fcs_trg_base::EMTHR2 ; -u_short fcs_trg_base::EMTHR3 ; +u_short fcs_trg_base::EMTHR3 ; //obsolete for 202207 +u_short fcs_trg_base::ELETHR0 ; +u_short fcs_trg_base::ELETHR1 ; +u_short fcs_trg_base::ELETHR2 ; +u_short fcs_trg_base::HADTHR0 ; u_short fcs_trg_base::HADTHR1 ; u_short fcs_trg_base::HADTHR2 ; -u_short fcs_trg_base::HADTHR3 ; -u_short fcs_trg_base::JETTHR1 ; -u_short fcs_trg_base::JETTHR2 ; +u_short fcs_trg_base::HADTHR3 ; //obsolete for 202207 +u_short fcs_trg_base::JETTHR1 ; //obsolete for 202207 +u_short fcs_trg_base::JETTHR2 ; //obsolete for 202207 +u_short fcs_trg_base::JPATHR2 ; +u_short fcs_trg_base::JPATHR1 ; +u_short fcs_trg_base::JPATHR0 ; +u_short fcs_trg_base::JPBCTHR2 ; +u_short fcs_trg_base::JPBCTHR1 ; +u_short fcs_trg_base::JPBCTHR0 ; +u_short fcs_trg_base::JPBCTHRD ; +u_short fcs_trg_base::JPDETHR2 ; +u_short fcs_trg_base::JPDETHR1 ; +u_short fcs_trg_base::JPDETHR0 ; +u_short fcs_trg_base::JPDETHRD ; u_short fcs_trg_base::ETOTTHR ; u_short fcs_trg_base::HTOTTHR ; u_short fcs_trg_base::EHTTHR ; @@ -99,8 +115,8 @@ void fcs_trg_base::init(const char* fname) for(int j=0;j1) LOG(ERR,"evt %d: S1_to_S2 IO: NS %d: ch %d: xing %d:%d: out 0x%02X, in 0x%02X", - evts,ns,i,x,t,s1_to_s2[i],s2_from_s1[i]) ; + if(log_level>0) LOG(ERR,"evt %d: S1_to_S2 IO: NS %c: ch %d: xing %d:%d: out 0x%02X, in 0x%02X", + evts,cns,i,x,t,s1_to_s2[i],s2_from_s1[i]) ; if(ns==0 && i<17) errs.io_s1_to_s2[0]++ ; else if(ns==0) errs.io_s1_to_s2[1]++ ; @@ -659,7 +711,7 @@ int fcs_trg_base::verify_event_io() } } - if(err==1 && log_level>1) { + if(err==1 && log_level>0) { for(int t=0;t<8;t++) { char ctmp ; @@ -701,7 +753,7 @@ int fcs_trg_base::dump_event_sim(int xing) for(int t=0;t<8;t++) { int d_sim = d_out.s1[i][j][k].s1_to_s2.d[t] ; - if(d_sim & fcs_trgDebug>0) + if(d_sim && fcs_trgDebug>0) printf("S1 sim: %d:%d:%d - xing %d:%d, dta %d\n", i,j,k,xing,t,d_sim) ; } @@ -744,7 +796,26 @@ int fcs_trg_base::verify_event_sim(int xing) int s3_failed = 0 ; for(int i=0;i0) { - LOG(ERR,"evt %d: S1 sim: %d:%d:%d - xing %d:%d: sim 0x%02X, dta 0x%02X %c",evts,i,j,k, + LOG(ERR,"evt %d: S1 sim: %c:%c:%d - xing %d:%d: sim 0x%02X, dta 0x%02X %c",evts,cns,cdet,k, xing,t, d_sim, d_i,d_sim!=d_i?'*':' ') ; @@ -793,7 +864,7 @@ int fcs_trg_base::verify_event_sim(int xing) } } - if(want_log && log_level>0) { + if(want_log && log_level>4) { u_int s1_bits = 0 ; for(int c=0;c<32;c++) { int sum = 0 ; @@ -802,7 +873,7 @@ int fcs_trg_base::verify_event_sim(int xing) LOG(ERR,"ch %2d: t %d: dta %d",c,t,d_in[xing].s1[i][j][k].adc[c].d[t]) ; } - LOG(ERR," sum %d, ped %d, sum-ped %d, ht thresh %d",sum,p_g[i][j][k][c].ped,sum-p_g[i][j][k][c].ped,ht_threshold[j]) ; + //LOG(ERR," sum %d, ped %d, sum-ped %d, ht thresh %d",sum,p_g[i][j][k][c].ped,sum-p_g[i][j][k][c].ped,ht_threshold[j]) ; sum -= p_g[i][j][k][c].ped ; if(sum > ht_threshold[j]) s1_bits |= (1<0) { - LOG(ERR,"evt %d: S2 sim: %d:%d - xing %d:%d: sim 0x%02X, dta 0x%02X%c",evts,i,j, + LOG(ERR,"evt %d: S2 sim: %c:%d - xing %d:%d: sim 0x%02X, dta 0x%02X%c",evts,cns,j, xing,t, d_sim, d_i,ctmp) ; } if(want_print && log_level>3) { - printf("evt %d: S2 sim: %d:%d: - xing %d:%d: sim %d, dta %d %s\n",evts,i,j, + printf("evt %d: S2 sim: %c:%d: - xing %d:%d: sim %d, dta %d %s\n",evts,cns,j, xing,t, d_sim, d_i,want_log?"ERROR":"") ; @@ -930,7 +1007,8 @@ int fcs_trg_base::verify_event_sim(int xing) // type==0 if we only want to compare data from actual DAQ files // type==1 if this is a GEANT simulation and there are no actual DEP boards -u_short fcs_trg_base::run_event_sim(int xing, int type) +//u_short fcs_trg_base::run_event_sim(int xing, int type) +u_int fcs_trg_base::run_event_sim(int xing, int type) { geom_t geo ; @@ -950,13 +1028,10 @@ u_short fcs_trg_base::run_event_sim(int xing, int type) geo.det = j ; for(int k=0;k +#include "fcs_trg_base.h" + + +/* + Changed from 8-timebin sum to highest ADC + 1 closes timebin. + + Also added simple peak-finding -- the maximum of the data + can't be on timebin 0 or 7. + + 202103 had a bug in the peak finder -- fixed in 202109 +*/ + + + +void fcs_trg_base::stage_0_202109(adc_tick_t adc, geom_t geo, ped_gain_t *pg, u_int *dta_out) +{ + int sum = 0 ; + int peak = 0 ; + int last = 0 ; + + for(int tb=0;tb<8;tb++) { + u_short radc = adc.d[tb] ; + + switch(tb) { + case 0 : + last = radc ; + sum = radc ; + peak = 0 ; + break ; + case 1 : + if(radc>sum) peak |= 1 ; + sum += radc ; + last = radc ; + break ; + case 2 : + sum += radc ; + last = radc ; + break ; + case 3 : + sum += radc ; + last = radc ; + break ; + case 4 : + sum += radc ; + last = radc ; + break ; + case 5 : + sum += radc ; + last = radc ; + break ; + case 6 : + sum += radc ; + last = radc ; + break ; + case 7 : + default : + //printf("radc %d, last %d, peak %d\n",radc,last,peak) ; + + if(radc>=last || peak==0) { + sum = 0 ; + } + else { + sum += radc ; + + sum -= pg?pg->ped:0 ; // ped is now only 3*ch_ped! + if(sum < 0) sum = 0 ; + + if(sum>0 && fcs_trgDebug>=2){ + if(geo.det<2){ + printf("ns=%1d det=%1d dep=%2d ch=%2d sum=%6d gain=%6d s*g=%6d pT=%6.3f\n", + geo.ns,geo.det,geo.dep,geo.ch, + sum,pg->gain,(sum*pg->gain)>>6, + 0.00024711*((sum*pg->gain)>>6) ); + }else{ + printf("ns=%1d det=%1d dep=%2d ch=%2d sum=%6d gain=%6d s*g=%6d MIP=%5.3f\n", + geo.ns,geo.det,geo.dep,geo.ch, + sum,pg->gain,(sum*pg->gain)>>6, + float((sum*pg->gain)>>6)/100.0); + } + } + + sum *= pg?pg->gain:0x100 ; // note that in FY21+ gain==1.0 is 0x100 + sum >>= 8 ; // see note above + } + + break ; + } + } + + //printf("... IN S0: %d\n",sum) ; + + *dta_out = sum ; +} diff --git a/StRoot/RTS/src/TRG_FCS/stage_1_202201.cxx b/StRoot/RTS/src/TRG_FCS/stage_1_202201.cxx index 5dbd10893d9..8b39f241a38 100644 --- a/StRoot/RTS/src/TRG_FCS/stage_1_202201.cxx +++ b/StRoot/RTS/src/TRG_FCS/stage_1_202201.cxx @@ -27,7 +27,9 @@ void fcs_trg_base::stage_1_202201(u_int s0[], geom_t geo, link_t *output) // Tonko: new 16-Feb-21 // stage_params[0][2] overrides the algo - if((stage_params[0][2]&0x3)==1) geo.det = 2 ; // force FPRE "high tower lookalike" + + // nah, not yet since stage_params doesn't know about DEPs + //if((stage_params[0][2]&0x3)==1) geo.det = 2 ; // force FPRE "high tower lookalike" // debugging marker in the stream, only for FPRE algo if(stage_params[0][2]&4) { diff --git a/StRoot/RTS/src/TRG_FCS/stage_2_202203.cxx b/StRoot/RTS/src/TRG_FCS/stage_2_202203.cxx index 22958e99fd1..d467d3a9763 100644 --- a/StRoot/RTS/src/TRG_FCS/stage_2_202203.cxx +++ b/StRoot/RTS/src/TRG_FCS/stage_2_202203.cxx @@ -228,9 +228,12 @@ void fcs_trg_base::stage_2_202203(link_t ecal[], link_t hcal[], link_t pres[], em[ns][r][c]=0; had[ns][r][c]=0; u_int h128 = h*128 ; - if(h128 < esum[ns][r][c] * EM_HERATIO_THR){ + +// Tonko: matches newest Christian code +// if(h128 < esum[ns][r][c] * EM_HERATIO_THR){ + if(h128 <= esum[ns][r][c] * EM_HERATIO_THR){ em[ns][r][c]=1; - if(sum[ns][r][c] > EMTHR1){ + if(sum[ns][r][c] > EMTHR1){ EM1 = 1; if(epdcoin[ns][r][c]==0) {GAM1 = 1;} else {ELE1 = 1;} @@ -308,7 +311,8 @@ void fcs_trg_base::stage_2_202203(link_t ecal[], link_t hcal[], link_t pres[], output[0].d[4] = JP1 + (JP2 <<1); output[0].d[5] = ETOT + (HTOT<<1); output[0].d[6] = (fpre_or<<2) | (hcal_ht<<1) | (ecal_ht); //HT - output[0].d[7] = 0xCD ; +// output[0].d[7] = 0xCD ; + output[0].d[7] = 0 ; // upper 8 bits output[1].d[0] = 0 ; @@ -318,7 +322,8 @@ void fcs_trg_base::stage_2_202203(link_t ecal[], link_t hcal[], link_t pres[], output[1].d[4] = 0 ; output[1].d[5] = 0 ; output[1].d[6] = 0 ; - output[1].d[7] = 0xAB ; +// output[1].d[7] = 0xAB ; + output[1].d[7] = 0 ; if(fcs_trgDebug>=1){ printf("STG2 NS%1d = %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x\n", diff --git a/StRoot/RTS/src/TRG_FCS/stage_2_202207.cxx b/StRoot/RTS/src/TRG_FCS/stage_2_202207.cxx new file mode 100644 index 00000000000..9bdb968d0d6 --- /dev/null +++ b/StRoot/RTS/src/TRG_FCS/stage_2_202207.cxx @@ -0,0 +1,371 @@ +#include +#include +#include + +#include "fcs_trg_base.h" +#include "fcs_ecal_epd_mask.h" + +// Modifed from stage_2_JP5_202206.cxx + +namespace { + //version2 with top2 & bottom2 rows in trigger, missing far side column + static const int EtoHmap[15][9][2] = { + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 1, 0},{ 1, 1},{ 1, 1},{ 1, 2},{ 1, 2},{ 1, 3},{ 1, 4},{ 1, 4},{ 1, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 4, 0},{ 4, 1},{ 4, 1},{ 4, 2},{ 4, 2},{ 4, 3},{ 4, 4},{ 4, 4},{ 4, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 7, 0},{ 7, 1},{ 7, 1},{ 7, 2},{ 7, 2},{ 7, 3},{ 7, 4},{ 7, 4},{ 7, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}} + } ; + + static const int EtoH3map[15][9][4] = { + {{-1,-1,-1, 0},{-1,-1, 0, 1},{-1,-1, 1, 2},{-1,-1, 1, 2},{-1,-1, 2, 3},{-1,-1, 2, 3},{-1,-1, 3, 4},{-1,-1, 4,-1},{-1,-1, 4,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 5,-1,10},{ 5, 6,10,11},{ 6, 7,11,12},{ 6, 7,11,12},{ 7, 8,12,13},{ 7, 8,12,13},{ 8, 9,13,14},{ 9,-1,14,-1},{ 9,-1,14,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,15,-1,20},{15,16,20,21},{16,17,21,22},{16,17,21,22},{17,18,22,23},{17,18,22,23},{18,19,23,24},{19,-1,24,-1},{19,-1,24,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,30,-1,35},{30,31,35,36},{31,32,36,37},{31,32,36,37},{32,33,37,38},{32,33,37,38},{33,34,38,39},{34,-1,39,-1},{34,-1,39,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,40,-1,-1},{40,41,-1,-1},{41,42,-1,-1},{41,42,-1,-1},{42,43,-1,-1},{42,43,-1,-1},{43,44,-1,-1},{44,-1,-1,-1},{44,-1,-1,-1}} + }; +} + +void fcs_trg_base::stage_2_202207(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[], u_short* s2_to_dsm) +{ + int ns=geo.ns; + if(fcs_trgDebug>=2) printf("Stage2v1 ns=%d\n",ns); + static int first=0; + // creating 2x2 row/column address map when called first time + static u_int ETbTdep[16][10]; //DEP# + static u_int ETbTadr[16][10]; //Input Link data address + static u_int HTbTdep[10][6]; //DEP# + static u_int HTbTadr[10][6]; //Input Link data address + if(first==0){ + first=1; + //making map of 2x2 Ecal Sums of [4][4] + for(int r=0; r<16; r++){ + printf("Ecal r=%2d : ",r); + for(int c=0; c<10; c++){ + ETbTdep[r][c]= c/2 + (r/4)*5; + ETbTadr[r][c]= c%2 + (r%4)*2; + printf("%2d-%1d ",ETbTdep[r][c],ETbTadr[r][c]); + } + printf("\n"); + } + //making map of 2x2 Hcal sums of [10][6] + for(int r=0; r<10; r++){ + printf("HCal r=%2d : ",r); + for(int c=0; c<6; c++){ + if (r==0){ + HTbTdep[r][c]= 6; + HTbTadr[r][c]= c; + }else if(r==9){ + HTbTdep[r][c]= 7; + HTbTadr[r][c]= c; + }else{ + HTbTdep[r][c]= c/2 + ((r-1)/4)*3; + HTbTadr[r][c]= c%2 + ((r-1)%4)*2; + } + printf("%2d-%1d ",HTbTdep[r][c],HTbTadr[r][c]); + } + printf("\n"); + } + } + + // Ecal 2x2 "HT" trigger + int ecal_ht = 0 ; + for(int i=0;i EHTTHR) ecal_ht |= 1 ; + } + } + + // Hcal 2x2 "HT" trigger + int hcal_ht = 0 ; + for(int i=0;i HHTTHR) hcal_ht |= 1 ; + } + } + + // Pres OR trigger + int fpre_or = 0 ; + for(int i=0;i=2) printf("H4x4 "); + for(int c=0; c<5; c++){ + hsum[ns][r][c] + = hcal[HTbTdep[r ][c ]].d[HTbTadr[r ][c ]] + + hcal[HTbTdep[r ][c+1]].d[HTbTadr[r ][c+1]] + + hcal[HTbTdep[r+1][c ]].d[HTbTadr[r+1][c ]] + + hcal[HTbTdep[r+1][c+1]].d[HTbTadr[r+1][c+1]]; + //if(hsum[r][c] > 0xff) hsum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + if(fcs_trgDebug>=2) printf("%5d ",hsum[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + //PRES for QA + if(fcs_trgDebug>0){ + for(int dep=0; dep<6; dep++) { + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1; + } + } + } + } + if(fcs_trgDebug>=2){ + for(int dep=0; dep<6; dep++) { + printf("PRES NS%1d DEP%1d : ",ns,dep); + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1; + printf("%1d", (pres[dep].d[j]>>k)&0x1); + } + printf(" "); + } + printf("\n"); + } + } + + //compute overlapping Ecal 4x4 sums of [15][9] + //take ratio with the closest hcal 4x4 + //u_int esum[15][9]; + //u_int sum[15][9]; + //float ratio[15][9]; + u_int EM2 =0, EM1 =0, EM0=0, EM3=0; + u_int ELE2=0, ELE1=0, ELE0=0; + u_int HAD2=0, HAD1=0, HAD0=0; + u_int ETOT=0, HTOT=0; + for(int r=0; r<15; r++){ + if(fcs_trgDebug>=2) printf("E4x4 "); + for(int c=0; c<9; c++){ + esum[ns][r][c] + = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]] + + ecal[ETbTdep[r ][c+1]].d[ETbTadr[r ][c+1]] + + ecal[ETbTdep[r+1][c ]].d[ETbTadr[r+1][c ]] + + ecal[ETbTdep[r+1][c+1]].d[ETbTadr[r+1][c+1]]; + //if(esum[r][c] > 0xff) esum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + + // locate the closest hcal + u_int h=hsum[ns][EtoHmap[r][c][0]][EtoHmap[r][c][1]]; + + // locate the max 2x2 hcal + u_int hmax=0; + for(int iz=0; iz<4; iz++){ + int iHCalID = EtoH3map[r][c][iz]; + if(iHCalID < 0) continue; + int irow = iHCalID/5; + int icol = iHCalID%5; + if(hmax < hsum[ns][irow][icol]) hmax = hsum[ns][irow][icol]; + } + + //if(h > 0 || hmax > 0) printf("Checking: %d, %d\n", h, hmax); + + // E+H sum + sum[ns][r][c] = esum[ns][r][c] + h; + + //in VHDL we will do esum>hsum*threshold. Ratio is for human only + if(sum[ns][r][c]==0) { + ratio[ns][r][c]=0.0; + }else{ + ratio[ns][r][c] = float(esum[ns][r][c]) / float(sum[ns][r][c]); + } + + //check EPD hits using the mask + epdcoin[ns][r][c]=0; + for(int dep=0; dep<6; dep++){ + int mask; + if(fcs_readPresMaskFromText==0){ + mask = fcs_ecal_epd_mask[r][c][dep]; //from include file + }else{ + mask = PRES_MASK[r][c][dep]; //from static which was from text file + } + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + if( (mask >> (j*8 + k)) & 0x1) { //if this is 0, don't even put the logic in VHDL + epdcoin[ns][r][c] |= (pres[dep].d[j] >> k) & 0x1; + } + } + } + } + + // integer multiplication as in VHDL! + // ratio thresholds are in fixed point integer where 1.0==128 + u_int h128 = h*128 ; + u_int hmax128 = hmax*128 ; + + if(hmax128 < esum[ns][r][c] * EM_HERATIO_THR){ + if(esum[ns][r][c] > EMTHR2) EM2 = 1; + if(esum[ns][r][c] > EMTHR1) EM1 = 1; + if(esum[ns][r][c] > EMTHR0) EM0 = 1; + if(esum[ns][r][c] > ELETHR2) EM3 = 1; //Using ELE Thr2 + if(epdcoin[ns][r][c]==1){ + if(esum[ns][r][c] > ELETHR2) ELE2 = 1; + if(esum[ns][r][c] > ELETHR1) ELE1 = 1; + if(esum[ns][r][c] > ELETHR0) ELE0 = 1; + } + } + + if(h128 > esum[ns][r][c] * HAD_HERATIO_THR){ + if(sum[ns][r][c] > HADTHR0) HAD0 = 1; + if(sum[ns][r][c] > HADTHR1) HAD1 = 1; + if(sum[ns][r][c] > HADTHR2) HAD2 = 1; + } + if(fcs_trgDebug>=2) printf("%5d %1d %3.2f ",esum[ns][r][c],epdcoin[ns][r][c],ratio[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + //5 square JP + int e_col_start[5] = { 0, 0, 0, 3, 3}; //these are 2x2 row/col + int e_col_stop[5] = { 3, 6, 6, 9, 9}; + int e_row_start[5] = { 3, 0, 5, 0, 5}; + int e_row_stop[5] = {12,10,15,10,15}; + int h_col_start[5] = { 0, 0, 0, 2, 2}; + int h_col_stop[5] = { 2, 3, 3, 5, 5}; + int h_row_start[5] = { 2, 0, 3, 0, 3}; + int h_row_stop[5] = { 7, 6, 9, 6, 9}; + int JP2[5] = {0,0,0,0,0}; + int JP1[5] = {0,0,0,0,0}; + int JP0[5] = {0,0,0,0,0}; + int JPd[5] = {0,0,0,0,0}; + for(int i=0; i<5; i++){ + jet[ns][i]=0; + for(int c=e_col_start[i]; c<=e_col_stop[i]; c++){ + for(int r=e_row_start[i]; r<=e_row_stop[i]; r++){ + if((i==1 || i==2) && (c==0 || c==1) && (r>=5 && r<=10)) continue; //cutout + jet[ns][i] += ecal[ETbTdep[r][c]].d[ETbTadr[r][c]]; + } + } + for(int c=h_col_start[i]; c<=h_col_stop[i]; c++){ + for(int r=h_row_start[i]; r<=h_row_stop[i]; r++){ + if((i==1 || i==2) && (c==0) && (r>=3 && r<=6)) continue; //cutout + jet[ns][i] += hcal[HTbTdep[r][c]].d[HTbTadr[r][c]]; + } + } + if(jet[ns][i]>0xff) jet[ns][i]=0xff; + if(i==0){ //JPA + if(jet[ns][i]>JPATHR2) JP2[i] = 1; + if(jet[ns][i]>JPATHR1) JP1[i] = 1; + if(jet[ns][i]>JPATHR0) JP0[i] = 1; + }else if(i==1 || i==2){ //JPB and JPC + if(jet[ns][i]>JPBCTHR2) JP2[i] = 1; + if(jet[ns][i]>JPBCTHR1) JP1[i] = 1; + if(jet[ns][i]>JPBCTHR0) JP0[i] = 1; + if(jet[ns][i]>JPBCTHRD) JPd[i] = 1; + }else{ //JPD and JPE + if(jet[ns][i]>JPDETHR2) JP2[i] = 1; + if(jet[ns][i]>JPDETHR1) JP1[i] = 1; + if(jet[ns][i]>JPDETHR0) JP0[i] = 1; + if(jet[ns][i]>JPDETHRD) JPd[i] = 1; + } + } + if(fcs_trgDebug>=2) printf("JP5 = %3d %3d %3d %3d %3d\n",jet[ns][0],jet[ns][1],jet[ns][2],jet[ns][3],jet[ns][4]); + + //Ecal sub-crate sum + u_int esub[4]; + esub[0] = esum[ns][ 0][0]+esum[ns][ 0][2]+esum[ns][ 0][4]+esum[ns][ 0][6]+esum[ns][ 0][8] + + esum[ns][ 2][0]+esum[ns][ 2][2]+esum[ns][ 2][4]+esum[ns][ 2][6]+esum[ns][ 2][8]; + esub[1] = esum[ns][ 4][0]+esum[ns][ 4][2]+esum[ns][ 4][4]+esum[ns][ 4][6]+esum[ns][ 4][8] + + esum[ns][ 6][0]+esum[ns][ 6][2]+esum[ns][ 6][4]+esum[ns][ 6][6]+esum[ns][ 6][8]; + esub[2] = esum[ns][ 8][0]+esum[ns][ 8][2]+esum[ns][ 8][4]+esum[ns][ 8][6]+esum[ns][ 8][8] + + esum[ns][10][0]+esum[ns][10][2]+esum[ns][10][4]+esum[ns][10][6]+esum[ns][10][8]; + esub[3] = esum[ns][12][0]+esum[ns][12][2]+esum[ns][12][4]+esum[ns][12][6]+esum[ns][12][8] + + esum[ns][14][0]+esum[ns][14][2]+esum[ns][14][4]+esum[ns][14][6]+esum[ns][14][8]; + for(int i=0; i<4; i++) if(esub[i]>0xff) esub[i]=0xff; + + //Hcal sub-crate sum + u_int hsub[4]; + hsub[0] = hsum[ns][ 1][0]+hsum[ns][ 1][2]+hsum[ns][ 1][4]; + hsub[1] = hsum[ns][ 3][0]+hsum[ns][ 3][2]+hsum[ns][ 3][4]; + hsub[2] = hsum[ns][ 5][0]+hsum[ns][ 5][2]+hsum[ns][ 5][4]; + hsub[3] = hsum[ns][ 7][0]+hsum[ns][ 7][2]+hsum[ns][ 7][4]; + for(int i=0; i<4; i++) if(hsub[i]>0xff) hsub[i]=0xff; + + //total ET + etot[ns] = esub[0] + esub[1] + esub[2] + esub[3]; + htot[ns] = hsub[0] + hsub[1] + hsub[2] + hsub[3]; + if(etot[ns]>ETOTTHR) ETOT=1; + if(htot[ns]>HTOTTHR) HTOT=1; + if(fcs_trgDebug>=2) printf("E/H Tot = %3d %3d\n",etot[ns],htot[ns]); + + //sending output bits + output[0].d[0] = (EM0<<0) + (EM1<<1) + (EM2<<2) + (EM3<<3) + (ELE0<<4) + (ELE1<<5) + (ELE2<<6) + (fpre_or<<7); + output[1].d[0] = (HAD0<<0) + (HAD1<<1) + (HAD2<<2) + (0<<3) + (ecal_ht<<4) + (hcal_ht<<5) + (ETOT<<6) + (HTOT<<7); + output[0].d[1] = (JP2[0]<<0) + (JP2[1]<<1) + (JP2[2]<<2) + (JP2[3]<<3) + (JP2[4]<<4); + output[1].d[1] = (JP1[0]<<0) + (JP1[1]<<1) + (JP1[2]<<2) + (JP1[3]<<3) + (JP1[4]<<4); + output[0].d[2] = (JP0[0]<<0) + (JP0[1]<<1) + (JP0[2]<<2) + (JP0[3]<<3) + (JP0[4]<<4); + output[1].d[2] = (JPd[0]<<0) + (JPd[1]<<1) + (JPd[2]<<2) + (JPd[3]<<3) + (JPd[4]<<4); //JPd[0]==0 + output[0].d[3] = 0; + output[1].d[3] = 0; + output[1].d[4] = 0; + output[0].d[4] = 0; + output[0].d[5] = 0; + output[1].d[5] = 0; + output[0].d[6] = 0; + output[1].d[6] = 0; + output[0].d[7] = 0; + output[1].d[7] = 0; + + *s2_to_dsm = (ELE0<<0) + (ELE1<<1) + (ELE2<<2) + (EM3<<3) + + (ecal_ht<<4) + (hcal_ht<<5) + (ETOT<<6) + (HTOT<<7); + + if(fcs_trgDebug>=1){ + printf("FCS STG2 NS=%1d output = %02x %02x %02x %02x %02x %02x TCU=%04x\n", + ns, + output[0].d[0],output[1].d[0],output[0].d[1],output[1].d[1], + output[0].d[2],output[1].d[2],*s2_to_dsm); + } + + return ; +} diff --git a/StRoot/RTS/src/TRG_FCS/stage_2_JP5_202206.cxx b/StRoot/RTS/src/TRG_FCS/stage_2_JP5_202206.cxx new file mode 100644 index 00000000000..3bab101e3c3 --- /dev/null +++ b/StRoot/RTS/src/TRG_FCS/stage_2_JP5_202206.cxx @@ -0,0 +1,362 @@ +#include +#include +#include + +#include "fcs_trg_base.h" +#include "fcs_ecal_epd_mask.h" + +// Modifed from stage_2_202201.cxx -- Ting + +namespace { + //version2 with top2 & bottom2 rows in trigger, missing far side column + static const int EtoHmap[15][9][2] = { + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 1, 0},{ 1, 1},{ 1, 1},{ 1, 2},{ 1, 2},{ 1, 3},{ 1, 4},{ 1, 4},{ 1, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 4, 0},{ 4, 1},{ 4, 1},{ 4, 2},{ 4, 2},{ 4, 3},{ 4, 4},{ 4, 4},{ 4, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 7, 0},{ 7, 1},{ 7, 1},{ 7, 2},{ 7, 2},{ 7, 3},{ 7, 4},{ 7, 4},{ 7, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}} + } ; + + static const int EtoH3map[15][9][4] = { + {{-1,-1,-1, 0},{-1,-1, 0, 1},{-1,-1, 1, 2},{-1,-1, 1, 2},{-1,-1, 2, 3},{-1,-1, 2, 3},{-1,-1, 3, 4},{-1,-1, 4,-1},{-1,-1, 4,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 5,-1,10},{ 5, 6,10,11},{ 6, 7,11,12},{ 6, 7,11,12},{ 7, 8,12,13},{ 7, 8,12,13},{ 8, 9,13,14},{ 9,-1,14,-1},{ 9,-1,14,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,15,-1,20},{15,16,20,21},{16,17,21,22},{16,17,21,22},{17,18,22,23},{17,18,22,23},{18,19,23,24},{19,-1,24,-1},{19,-1,24,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,30,-1,35},{30,31,35,36},{31,32,36,37},{31,32,36,37},{32,33,37,38},{32,33,37,38},{33,34,38,39},{34,-1,39,-1},{34,-1,39,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,40,-1,-1},{40,41,-1,-1},{41,42,-1,-1},{41,42,-1,-1},{42,43,-1,-1},{42,43,-1,-1},{43,44,-1,-1},{44,-1,-1,-1},{44,-1,-1,-1}} + }; +} + +void fcs_trg_base::stage_2_JP5_202206(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) +{ + int ns=geo.ns; + if(fcs_trgDebug>=2) printf("Stage2v1 ns=%d\n",ns); + static int first=0; + // creating 2x2 row/column address map when called first time + static u_int ETbTdep[16][10]; //DEP# + static u_int ETbTadr[16][10]; //Input Link data address + static u_int HTbTdep[10][6]; //DEP# + static u_int HTbTadr[10][6]; //Input Link data address + if(first==0){ + first=1; + //making map of 2x2 Ecal Sums of [4][4] + for(int r=0; r<16; r++){ + printf("Ecal r=%2d : ",r); + for(int c=0; c<10; c++){ + ETbTdep[r][c]= c/2 + (r/4)*5; + ETbTadr[r][c]= c%2 + (r%4)*2; + printf("%2d-%1d ",ETbTdep[r][c],ETbTadr[r][c]); + } + printf("\n"); + } + //making map of 2x2 Hcal sums of [10][6] + for(int r=0; r<10; r++){ + printf("HCal r=%2d : ",r); + for(int c=0; c<6; c++){ + if (r==0){ + HTbTdep[r][c]= 6; + HTbTadr[r][c]= c; + }else if(r==9){ + HTbTdep[r][c]= 7; + HTbTadr[r][c]= c; + }else{ + HTbTdep[r][c]= c/2 + ((r-1)/4)*3; + HTbTadr[r][c]= c%2 + ((r-1)%4)*2; + } + printf("%2d-%1d ",HTbTdep[r][c],HTbTadr[r][c]); + } + printf("\n"); + } + } + + // Ecal 2x2 "HT" trigger + int ecal_ht = 0 ; + for(int i=0;i EHTTHR) ecal_ht |= 1 ; + } + } + + // Hcal 2x2 "HT" trigger + int hcal_ht = 0 ; + for(int i=0;i HHTTHR) hcal_ht |= 1 ; + } + } + + // Pres OR trigger + int fpre_or = 0 ; + for(int i=0;i=2) printf("H4x4 "); + for(int c=0; c<5; c++){ + hsum[ns][r][c] + = hcal[HTbTdep[r ][c ]].d[HTbTadr[r ][c ]] + + hcal[HTbTdep[r ][c+1]].d[HTbTadr[r ][c+1]] + + hcal[HTbTdep[r+1][c ]].d[HTbTadr[r+1][c ]] + + hcal[HTbTdep[r+1][c+1]].d[HTbTadr[r+1][c+1]]; + //if(hsum[r][c] > 0xff) hsum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + if(fcs_trgDebug>=2) printf("%5d ",hsum[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + //PRES for QA + if(fcs_trgDebug>0){ + for(int dep=0; dep<6; dep++) { + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1; + } + } + } + } + if(fcs_trgDebug>=2){ + for(int dep=0; dep<6; dep++) { + printf("PRES NS%1d DEP%1d : ",ns,dep); + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1; + printf("%1d", (pres[dep].d[j]>>k)&0x1); + } + printf(" "); + } + printf("\n"); + } + } + + //compute overlapping Ecal 4x4 sums of [15][9] + //take ratio with the closest hcal 4x4 + //u_int esum[15][9]; + //u_int sum[15][9]; + //float ratio[15][9]; + u_int EM1 =0, EM2 =0, EM3=0; + u_int GAM1=0, GAM2=0, GAM3=0; + u_int ELE1=0, ELE2=0, ELE3=0; + u_int HAD1=0, HAD2=0, HAD3=0; + u_int ETOT=0, HTOT=0; + for(int r=0; r<15; r++){ + if(fcs_trgDebug>=2) printf("E4x4 "); + for(int c=0; c<9; c++){ + esum[ns][r][c] + = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]] + + ecal[ETbTdep[r ][c+1]].d[ETbTadr[r ][c+1]] + + ecal[ETbTdep[r+1][c ]].d[ETbTadr[r+1][c ]] + + ecal[ETbTdep[r+1][c+1]].d[ETbTadr[r+1][c+1]]; + //if(esum[r][c] > 0xff) esum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + + // locate the closest hcal + u_int h=hsum[ns][EtoHmap[r][c][0]][EtoHmap[r][c][1]]; + + // locate the max 2x2 hcal + u_int hmax=0; + for(int iz=0; iz<4; iz++){ + int iHCalID = EtoH3map[r][c][iz]; + if(iHCalID < 0) continue; + int irow = iHCalID/5; + int icol = iHCalID%5; + if(hmax < hsum[ns][irow][icol]) hmax = hsum[ns][irow][icol]; + } + + //if(h > 0 || hmax > 0) printf("Checking: %d, %d\n", h, hmax); + + // E+H sum + sum[ns][r][c] = esum[ns][r][c] + h; + + //in VHDL we will do esum>hsum*threshold. Ratio is for human only + if(sum[ns][r][c]==0) { + ratio[ns][r][c]=0.0; + }else{ + ratio[ns][r][c] = float(esum[ns][r][c]) / float(sum[ns][r][c]); + } + + //check EPD hits using the mask + epdcoin[ns][r][c]=0; + for(int dep=0; dep<6; dep++){ + int mask; + if(fcs_readPresMaskFromText==0){ + mask = fcs_ecal_epd_mask[r][c][dep]; //from include file + }else{ + mask = PRES_MASK[r][c][dep]; //from static which was from text file + } + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + if( (mask >> (j*8 + k)) & 0x1) { //if this is 0, don't even put the logic in VHDL + epdcoin[ns][r][c] |= (pres[dep].d[j] >> k) & 0x1; + } + } + } + } + + // integer multiplication as in VHDL! + // ratio thresholds are in fixed point integer where 1.0==128 + u_int h128 = h*128 ; + u_int hmax128 = hmax*128 ; + + if(hmax128 < esum[ns][r][c] * EM_HERATIO_THR){ + if(esum[ns][r][c] > EMTHR1){ + EM1 = 1; + if(epdcoin[ns][r][c]==0) {GAM1 = 1;} + else {ELE1 = 1;} + } + if(esum[ns][r][c] > EMTHR2){ + EM2 = 1; + if(epdcoin[ns][r][c]==0) {GAM2 = 1;} + else {ELE2 = 1;} + } + if(esum[ns][r][c] > EMTHR3){ + EM3 = 1; + if(epdcoin[ns][r][c]==0) {GAM3 = 1;} + else {ELE3 = 1;} + } + } + + if(h128 > esum[ns][r][c] * HAD_HERATIO_THR){ + if(sum[ns][r][c] > HADTHR1) HAD1 = 1; + if(sum[ns][r][c] > HADTHR2) HAD2 = 1; + if(sum[ns][r][c] > HADTHR3) HAD3 = 1; + } + if(fcs_trgDebug>=2) printf("%5d %1d %3.2f ",esum[ns][r][c],epdcoin[ns][r][c],ratio[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + //5 square JP + int e_col_start[5] = { 0, 0, 0, 3, 3}; //these are 2x2 row/col + int e_col_stop[5] = { 3, 6, 6, 9, 9}; + int e_row_start[5] = { 3, 0, 5, 0, 5}; + int e_row_stop[5] = {12,10,15,10,15}; + int h_col_start[5] = { 0, 0, 0, 2, 2}; + int h_col_stop[5] = { 2, 3, 3, 5, 5}; + int h_row_start[5] = { 2, 0, 3, 0, 3}; + int h_row_stop[5] = { 7, 6, 9, 6, 9}; + int JP1[5] = {0,0,0,0,0}; + int JP2[5] = {0,0,0,0,0}; + for(int i=0; i<5; i++){ + jet[ns][i]=0; + for(int c=e_col_start[i]; c<=e_col_stop[i]; c++){ + for(int r=e_row_start[i]; r<=e_row_stop[i]; r++){ + if((i==1 || i==2) && (c==0 || c==1) && (r>=5 && r<=10)) continue; //cutout + jet[ns][i] += ecal[ETbTdep[r][c]].d[ETbTadr[r][c]]; + } + } + for(int c=h_col_start[i]; c<=h_col_stop[i]; c++){ + for(int r=h_row_start[i]; r<=h_row_stop[i]; r++){ + if((i==1 || i==2) && (c==0) && (r>=3 && r<=6)) continue; //cutout + jet[ns][i] += hcal[HTbTdep[r][c]].d[HTbTadr[r][c]]; + } + } + if(jet[ns][i]>0xff) jet[ns][i]=0xff; + if(jet[ns][i]>JETTHR1) JP1[i] = 1; + if(jet[ns][i]>JETTHR2) JP2[i] = 1; + } + if(fcs_trgDebug>=2) printf("JP5 = %3d %3d %3d %3d %3d\n",jet[ns][0],jet[ns][1],jet[ns][2],jet[ns][3],jet[ns][4]); + + //Ecal sub-crate sum + u_int esub[4]; + esub[0] = esum[ns][ 0][0]+esum[ns][ 0][2]+esum[ns][ 0][4]+esum[ns][ 0][6]+esum[ns][ 0][8] + + esum[ns][ 2][0]+esum[ns][ 2][2]+esum[ns][ 2][4]+esum[ns][ 2][6]+esum[ns][ 2][8]; + esub[1] = esum[ns][ 4][0]+esum[ns][ 4][2]+esum[ns][ 4][4]+esum[ns][ 4][6]+esum[ns][ 4][8] + + esum[ns][ 6][0]+esum[ns][ 6][2]+esum[ns][ 6][4]+esum[ns][ 6][6]+esum[ns][ 6][8]; + esub[2] = esum[ns][ 8][0]+esum[ns][ 8][2]+esum[ns][ 8][4]+esum[ns][ 8][6]+esum[ns][ 8][8] + + esum[ns][10][0]+esum[ns][10][2]+esum[ns][10][4]+esum[ns][10][6]+esum[ns][10][8]; + esub[3] = esum[ns][12][0]+esum[ns][12][2]+esum[ns][12][4]+esum[ns][12][6]+esum[ns][12][8] + + esum[ns][14][0]+esum[ns][14][2]+esum[ns][14][4]+esum[ns][14][6]+esum[ns][14][8]; + for(int i=0; i<4; i++) if(esub[i]>0xff) esub[i]=0xff; + + //Hcal sub-crate sum + u_int hsub[4]; + hsub[0] = hsum[ns][ 1][0]+hsum[ns][ 1][2]+hsum[ns][ 1][4]; + hsub[1] = hsum[ns][ 3][0]+hsum[ns][ 3][2]+hsum[ns][ 3][4]; + hsub[2] = hsum[ns][ 5][0]+hsum[ns][ 5][2]+hsum[ns][ 5][4]; + hsub[3] = hsum[ns][ 7][0]+hsum[ns][ 7][2]+hsum[ns][ 7][4]; + for(int i=0; i<4; i++) if(hsub[i]>0xff) hsub[i]=0xff; + + //total ET + etot[ns] = esub[0] + esub[1] + esub[2] + esub[3]; + htot[ns] = hsub[0] + hsub[1] + hsub[2] + hsub[3]; + if(etot[ns]>ETOTTHR) ETOT=1; + if(htot[ns]>HTOTTHR) HTOT=1; + if(fcs_trgDebug>=2) printf("E/H Tot = %3d %3d\n",etot[ns],htot[ns]); + + //sending output bits + output[0].d[0] = EM1 + (EM2 <<1) + (EM3 <<2); + output[0].d[1] = ELE1 + (ELE2<<1) + (ELE3<<2); + output[0].d[2] = GAM1 + (GAM2<<1) + (GAM3<<2); + output[0].d[3] = HAD1 + (HAD2<<1) + (HAD3<<2); + output[0].d[4] = (JP1[0] << 0) + (JP1[1]<<1) + (JP1[2]<<2) + (JP1[3]<<3) + (JP1[4]<<4); + output[0].d[5] = ETOT + (HTOT<<1); + output[0].d[6] = (fpre_or<<2) | (hcal_ht<<1) | (ecal_ht); //HT + output[0].d[7] = 0xCD ; + + // upper 8 bits + output[1].d[0] = 0 ; + output[1].d[1] = 0 ; + output[1].d[2] = 0 ; + output[1].d[3] = 0 ; + output[0].d[4] = (JP2[0] << 0) + (JP2[1]<<1) + (JP2[2]<<2) + (JP2[3]<<3) + (JP2[4]<<4); + output[1].d[5] = 0 ; + output[1].d[6] = 0 ; + output[1].d[7] = 0xAB ; + + if(fcs_trgDebug>=1){ + printf("FCS STG2 NS=%1d output = %02x %02x %02x %02x %02x %02x %02x %02x\n", + ns, + output[0].d[0],output[0].d[1],output[0].d[2],output[0].d[3], + output[0].d[4],output[0].d[5],output[0].d[6],output[0].d[7]); + } + + return ; +} diff --git a/StRoot/RTS/src/TRG_FCS/stage_2_JP6Carl_202205.cxx b/StRoot/RTS/src/TRG_FCS/stage_2_JP6Carl_202205.cxx new file mode 100644 index 00000000000..fd3d49ced3b --- /dev/null +++ b/StRoot/RTS/src/TRG_FCS/stage_2_JP6Carl_202205.cxx @@ -0,0 +1,340 @@ +#include +#include +#include + +#include "fcs_trg_base.h" +#include "fcs_ecal_epd_mask.h" + +// Modifed from stage_2_202201.cxx -- Ting + +namespace { + //version2 with top2 & bottom2 rows in trigger, missing far side column + static const int EtoHmap[15][9][2] = { + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 1, 0},{ 1, 1},{ 1, 1},{ 1, 2},{ 1, 2},{ 1, 3},{ 1, 4},{ 1, 4},{ 1, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 4, 0},{ 4, 1},{ 4, 1},{ 4, 2},{ 4, 2},{ 4, 3},{ 4, 4},{ 4, 4},{ 4, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 7, 0},{ 7, 1},{ 7, 1},{ 7, 2},{ 7, 2},{ 7, 3},{ 7, 4},{ 7, 4},{ 7, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}} + } ; + + static const int EtoH3map[15][9][4] = { + {{-1,-1,-1, 0},{-1,-1, 0, 1},{-1,-1, 1, 2},{-1,-1, 1, 2},{-1,-1, 2, 3},{-1,-1, 2, 3},{-1,-1, 3, 4},{-1,-1, 4,-1},{-1,-1, 4,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 5,-1,10},{ 5, 6,10,11},{ 6, 7,11,12},{ 6, 7,11,12},{ 7, 8,12,13},{ 7, 8,12,13},{ 8, 9,13,14},{ 9,-1,14,-1},{ 9,-1,14,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,15,-1,20},{15,16,20,21},{16,17,21,22},{16,17,21,22},{17,18,22,23},{17,18,22,23},{18,19,23,24},{19,-1,24,-1},{19,-1,24,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,30,-1,35},{30,31,35,36},{31,32,36,37},{31,32,36,37},{32,33,37,38},{32,33,37,38},{33,34,38,39},{34,-1,39,-1},{34,-1,39,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,40,-1,-1},{40,41,-1,-1},{41,42,-1,-1},{41,42,-1,-1},{42,43,-1,-1},{42,43,-1,-1},{43,44,-1,-1},{44,-1,-1,-1},{44,-1,-1,-1}} + }; +} + +void fcs_trg_base::stage_2_JP6Carl_202205(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) +{ + int ns=geo.ns; + if(fcs_trgDebug>=2) printf("Stage2v1 ns=%d\n",ns); + static int first=0; + // creating 2x2 row/column address map when called first time + static u_int ETbTdep[16][10]; //DEP# + static u_int ETbTadr[16][10]; //Input Link data address + static u_int HTbTdep[10][6]; //DEP# + static u_int HTbTadr[10][6]; //Input Link data address + if(first==0){ + first=1; + //making map of 2x2 Ecal Sums of [4][4] + for(int r=0; r<16; r++){ + printf("Ecal r=%2d : ",r); + for(int c=0; c<10; c++){ + ETbTdep[r][c]= c/2 + (r/4)*5; + ETbTadr[r][c]= c%2 + (r%4)*2; + printf("%2d-%1d ",ETbTdep[r][c],ETbTadr[r][c]); + } + printf("\n"); + } + //making map of 2x2 Hcal sums of [10][6] + for(int r=0; r<10; r++){ + printf("HCal r=%2d : ",r); + for(int c=0; c<6; c++){ + if (r==0){ + HTbTdep[r][c]= 6; + HTbTadr[r][c]= c; + }else if(r==9){ + HTbTdep[r][c]= 7; + HTbTadr[r][c]= c; + }else{ + HTbTdep[r][c]= c/2 + ((r-1)/4)*3; + HTbTadr[r][c]= c%2 + ((r-1)%4)*2; + } + printf("%2d-%1d ",HTbTdep[r][c],HTbTadr[r][c]); + } + printf("\n"); + } + } + + //compute overlapping Hcal 4x4 sum of [9][5] + //u_int hsum[9][5]; + for(int r=0; r<9; r++){ + if(fcs_trgDebug>=2) printf("H4x4 "); + for(int c=0; c<5; c++){ + hsum[ns][r][c] + = hcal[HTbTdep[r ][c ]].d[HTbTadr[r ][c ]] + + hcal[HTbTdep[r ][c+1]].d[HTbTadr[r ][c+1]] + + hcal[HTbTdep[r+1][c ]].d[HTbTadr[r+1][c ]] + + hcal[HTbTdep[r+1][c+1]].d[HTbTadr[r+1][c+1]]; + //if(hsum[r][c] > 0xff) hsum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + if(fcs_trgDebug>=2) printf("%5d ",hsum[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + // Ecal 2x2 "HT" trigger + int ecal_ht = 0 ; + for(int i=0;i EHTTHR) ecal_ht |= 1 ; + } + } + + // Hcal 2x2 "HT" trigger + int hcal_ht = 0 ; + for(int i=0;i HHTTHR) hcal_ht |= 1 ; + } + } + + // Pres OR trigger + int fpre_or = 0 ; + for(int i=0;i=2) printf("E4x4 "); + for(int c=0; c<9; c++){ + esum[ns][r][c] + = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]] + + ecal[ETbTdep[r ][c+1]].d[ETbTadr[r ][c+1]] + + ecal[ETbTdep[r+1][c ]].d[ETbTadr[r+1][c ]] + + ecal[ETbTdep[r+1][c+1]].d[ETbTadr[r+1][c+1]]; + //if(esum[r][c] > 0xff) esum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + + // locate the closest hcal + u_int h=hsum[ns][EtoHmap[r][c][0]][EtoHmap[r][c][1]]; + + // locate the max 2x2 hcal + u_int hmax=0; + for(int iz=0; iz<4; iz++){ + int iHCalID = EtoH3map[r][c][iz]; + if(iHCalID < 0) continue; + int irow = iHCalID/5; + int icol = iHCalID%5; + if(hmax < hsum[ns][irow][icol]) hmax = hsum[ns][irow][icol]; + } + + //if(h > 0 || hmax > 0) printf("Checking: %d, %d\n", h, hmax); + + // E+H sum + sum[ns][r][c] = esum[ns][r][c] + h; + + //in VHDL we will do esum>hsum*threshold. Ratio is for human only + if(sum[ns][r][c]==0) { + ratio[ns][r][c]=0.0; + }else{ + ratio[ns][r][c] = float(esum[ns][r][c]) / float(sum[ns][r][c]); + } + + //check EPD hits using the mask + epdcoin[ns][r][c]=0; + for(int dep=0; dep<6; dep++){ + int mask; + if(fcs_readPresMaskFromText==0){ + mask = fcs_ecal_epd_mask[r][c][dep]; //from include file + }else{ + mask = PRES_MASK[r][c][dep]; //from static which was from text file + } + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + if( (mask >> (j*8 + k)) & 0x1) { //if this is 0, don't even put the logic in VHDL + epdcoin[ns][r][c] |= (pres[dep].d[j] >> k) & 0x1; + } + } + } + } + + // integer multiplication as in VHDL! + // ratio thresholds are in fixed point integer where 1.0==128 + u_int h128 = h*128 ; + u_int hmax128 = hmax*128 ; + + if(hmax128 < esum[ns][r][c] * EM_HERATIO_THR){ + if(esum[ns][r][c] > EMTHR1){ + EM1 = 1; + if(epdcoin[ns][r][c]==0) {GAM1 = 1;} + else {ELE1 = 1;} + } + if(esum[ns][r][c] > EMTHR2){ + EM2 = 1; + if(epdcoin[ns][r][c]==0) {GAM2 = 1;} + else {ELE2 = 1;} + } + if(esum[ns][r][c] > EMTHR3){ + EM3 = 1; + if(epdcoin[ns][r][c]==0) {GAM3 = 1;} + else {ELE3 = 1;} + } + } + + if(h128 > esum[ns][r][c] * HAD_HERATIO_THR){ + if(sum[ns][r][c] > HADTHR1) HAD1 = 1; + if(sum[ns][r][c] > HADTHR2) HAD2 = 1; + if(sum[ns][r][c] > HADTHR3) HAD3 = 1; + } + if(fcs_trgDebug>=2) printf("%5d %1d %3.2f ",esum[ns][r][c],epdcoin[ns][r][c],ratio[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + //Carl's 6 square JP + int e_col_start[3] = { 0, 1, 3}; //these are 2x2 row/col + int e_col_stop[3] = { 4, 5, 9}; + int e_row_start[2] = { 0, 5}; + int e_row_stop[2] = {10,15}; + int h_col_start[3] = { 0, 1, 2}; + int h_col_stop[3] = { 2, 3, 5}; + int h_row_start[2] = { 0, 3}; + int h_row_stop[2] = { 6, 9}; + int JP1[6] = {0,0,0,0,0,0}; + int JP2[6] = {0,0,0,0,0,0}; + int j=0; + for(int jc=0; jc<3; jc++){ + for(int jr=0; jr<2; jr++){ + jet[ns][j]=0; + for(int c=e_col_start[jc]; c<=e_col_stop[jc]; c++){ + for(int r=e_row_start[jr]; r<=e_row_stop[jr]; r++){ + jet[ns][j] += ecal[ETbTdep[r][c]].d[ETbTadr[r][c]]; + } + } + for(int c=h_col_start[jc]; c<=h_col_stop[jc]; c++){ + for(int r=h_row_start[jr]; r<=h_row_stop[jr]; r++){ + jet[ns][j] += hcal[HTbTdep[r][c]].d[HTbTadr[r][c]]; + } + } + if(jet[ns][j]>0xff) jet[ns][j]=0xff; + if(jet[ns][j]>JETTHR1) JP1[j] = 1; + if(jet[ns][j]>JETTHR2) JP2[j] = 1; + j++; + } + } + if(fcs_trgDebug>=2) printf("JP6C = %3d %3d %3d %3d %3d %3d\n",jet[ns][0],jet[ns][1],jet[ns][2],jet[ns][3],jet[ns][4],jet[ns][5]); + + //Ecal sub-crate sum + u_int esub[4]; + esub[0] = esum[ns][ 0][0]+esum[ns][ 0][2]+esum[ns][ 0][4]+esum[ns][ 0][6]+esum[ns][ 0][8] + + esum[ns][ 2][0]+esum[ns][ 2][2]+esum[ns][ 2][4]+esum[ns][ 2][6]+esum[ns][ 2][8]; + esub[1] = esum[ns][ 4][0]+esum[ns][ 4][2]+esum[ns][ 4][4]+esum[ns][ 4][6]+esum[ns][ 4][8] + + esum[ns][ 6][0]+esum[ns][ 6][2]+esum[ns][ 6][4]+esum[ns][ 6][6]+esum[ns][ 6][8]; + esub[2] = esum[ns][ 8][0]+esum[ns][ 8][2]+esum[ns][ 8][4]+esum[ns][ 8][6]+esum[ns][ 8][8] + + esum[ns][10][0]+esum[ns][10][2]+esum[ns][10][4]+esum[ns][10][6]+esum[ns][10][8]; + esub[3] = esum[ns][12][0]+esum[ns][12][2]+esum[ns][12][4]+esum[ns][12][6]+esum[ns][12][8] + + esum[ns][14][0]+esum[ns][14][2]+esum[ns][14][4]+esum[ns][14][6]+esum[ns][14][8]; + for(int i=0; i<4; i++) if(esub[i]>0xff) esub[i]=0xff; + + //Hcal sub-crate sum + u_int hsub[4]; + hsub[0] = hsum[ns][ 1][0]+hsum[ns][ 1][2]+hsum[ns][ 1][4]; + hsub[1] = hsum[ns][ 3][0]+hsum[ns][ 3][2]+hsum[ns][ 3][4]; + hsub[2] = hsum[ns][ 5][0]+hsum[ns][ 5][2]+hsum[ns][ 5][4]; + hsub[3] = hsum[ns][ 7][0]+hsum[ns][ 7][2]+hsum[ns][ 7][4]; + for(int i=0; i<4; i++) if(hsub[i]>0xff) hsub[i]=0xff; + + //total ET + etot[ns] = esub[0] + esub[1] + esub[2] + esub[3]; + htot[ns] = hsub[0] + hsub[1] + hsub[2] + hsub[3]; + if(etot[ns]>ETOTTHR) ETOT=1; + if(htot[ns]>HTOTTHR) HTOT=1; + if(fcs_trgDebug>=2) printf("E/H Tot = %3d %3d\n",etot[ns],htot[ns]); + + //sending output bits + output[0].d[0] = EM1 + (EM2 <<1) + (EM3 <<2); + output[0].d[1] = ELE1 + (ELE2<<1) + (ELE3<<2); + output[0].d[2] = GAM1 + (GAM2<<1) + (GAM3<<2); + output[0].d[3] = HAD1 + (HAD2<<1) + (HAD3<<2); + output[0].d[4] = (JP1[0] << 0) + (JP1[1]<<1) + (JP1[2]<<2) + (JP1[3]<<3) + (JP1[4]<<4) + (JP1[5]<<5); + output[0].d[5] = ETOT + (HTOT<<1); + output[0].d[6] = (fpre_or<<2) | (hcal_ht<<1) | (ecal_ht); //HT + output[0].d[7] = 0xCD ; + + // upper 8 bits + output[1].d[0] = 0 ; + output[1].d[1] = 0 ; + output[1].d[2] = 0 ; + output[1].d[3] = 0 ; + output[1].d[4] = (JP2[0] << 0) + (JP2[1]<<1) + (JP2[2]<<2) + (JP2[3]<<3) + (JP2[4]<<4) + (JP2[5]<<5); + output[1].d[5] = 0 ; + output[1].d[6] = 0 ; + output[1].d[7] = 0xAB ; + + if(fcs_trgDebug>=1){ + printf("FCS STG2 NS=%1d output = %02x %02x %02x %02x %02x %02x %02x %02x\n", + ns, + output[0].d[0],output[0].d[1],output[0].d[2],output[0].d[3], + output[0].d[4],output[0].d[5],output[0].d[6],output[0].d[7]); + } + + return ; +} diff --git a/StRoot/RTS/src/TRG_FCS/stage_2_JP6_202204.cxx b/StRoot/RTS/src/TRG_FCS/stage_2_JP6_202204.cxx new file mode 100644 index 00000000000..105cd1f3540 --- /dev/null +++ b/StRoot/RTS/src/TRG_FCS/stage_2_JP6_202204.cxx @@ -0,0 +1,365 @@ +#include +#include +#include + +#include "fcs_trg_base.h" +#include "fcs_ecal_epd_mask.h" + +// Modifed from stage_2_202201.cxx -- Ting + +namespace { + //version2 with top2 & bottom2 rows in trigger, missing far side column + static const int EtoHmap[15][9][2] = { + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}}, + { { 1, 0},{ 1, 1},{ 1, 1},{ 1, 2},{ 1, 2},{ 1, 3},{ 1, 4},{ 1, 4},{ 1, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}}, + { { 4, 0},{ 4, 1},{ 4, 1},{ 4, 2},{ 4, 2},{ 4, 3},{ 4, 4},{ 4, 4},{ 4, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}}, + { { 7, 0},{ 7, 1},{ 7, 1},{ 7, 2},{ 7, 2},{ 7, 3},{ 7, 4},{ 7, 4},{ 7, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}}, + { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}} + } ; + + static const int EtoH3map[15][9][4] = { + {{-1,-1,-1, 0},{-1,-1, 0, 1},{-1,-1, 1, 2},{-1,-1, 1, 2},{-1,-1, 2, 3},{-1,-1, 2, 3},{-1,-1, 3, 4},{-1,-1, 4,-1},{-1,-1, 4,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}}, + {{-1, 5,-1,10},{ 5, 6,10,11},{ 6, 7,11,12},{ 6, 7,11,12},{ 7, 8,12,13},{ 7, 8,12,13},{ 8, 9,13,14},{ 9,-1,14,-1},{ 9,-1,14,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}}, + {{-1,15,-1,20},{15,16,20,21},{16,17,21,22},{16,17,21,22},{17,18,22,23},{17,18,22,23},{18,19,23,24},{19,-1,24,-1},{19,-1,24,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}}, + {{-1,30,-1,35},{30,31,35,36},{31,32,36,37},{31,32,36,37},{32,33,37,38},{32,33,37,38},{33,34,38,39},{34,-1,39,-1},{34,-1,39,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}}, + {{-1,40,-1,-1},{40,41,-1,-1},{41,42,-1,-1},{41,42,-1,-1},{42,43,-1,-1},{42,43,-1,-1},{43,44,-1,-1},{44,-1,-1,-1},{44,-1,-1,-1}} + }; +} + +void fcs_trg_base::stage_2_JP6_202204(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[]) +{ + int ns=geo.ns; + if(fcs_trgDebug>=2) printf("Stage2v1 ns=%d\n",ns); + static int first=0; + // creating 2x2 row/column address map when called first time + static u_int ETbTdep[16][10]; //DEP# + static u_int ETbTadr[16][10]; //Input Link data address + static u_int HTbTdep[10][6]; //DEP# + static u_int HTbTadr[10][6]; //Input Link data address + if(first==0){ + first=1; + //making map of 2x2 Ecal Sums of [4][4] + for(int r=0; r<16; r++){ + printf("Ecal r=%2d : ",r); + for(int c=0; c<10; c++){ + ETbTdep[r][c]= c/2 + (r/4)*5; + ETbTadr[r][c]= c%2 + (r%4)*2; + printf("%2d-%1d ",ETbTdep[r][c],ETbTadr[r][c]); + } + printf("\n"); + } + //making map of 2x2 Hcal sums of [10][6] + for(int r=0; r<10; r++){ + printf("HCal r=%2d : ",r); + for(int c=0; c<6; c++){ + if (r==0){ + HTbTdep[r][c]= 6; + HTbTadr[r][c]= c; + }else if(r==9){ + HTbTdep[r][c]= 7; + HTbTadr[r][c]= c; + }else{ + HTbTdep[r][c]= c/2 + ((r-1)/4)*3; + HTbTadr[r][c]= c%2 + ((r-1)%4)*2; + } + printf("%2d-%1d ",HTbTdep[r][c],HTbTadr[r][c]); + } + printf("\n"); + } + } + + // Ecal 2x2 "HT" trigger + int ecal_ht = 0 ; + for(int i=0;i EHTTHR) ecal_ht |= 1 ; + } + } + + // Hcal 2x2 "HT" trigger + int hcal_ht = 0 ; + for(int i=0;i HHTTHR) hcal_ht |= 1 ; + } + } + + // Pres OR trigger + int fpre_or = 0 ; + for(int i=0;i=2) printf("H4x4 "); + for(int c=0; c<5; c++){ + hsum[ns][r][c] + = hcal[HTbTdep[r ][c ]].d[HTbTadr[r ][c ]] + + hcal[HTbTdep[r ][c+1]].d[HTbTadr[r ][c+1]] + + hcal[HTbTdep[r+1][c ]].d[HTbTadr[r+1][c ]] + + hcal[HTbTdep[r+1][c+1]].d[HTbTadr[r+1][c+1]]; + //if(hsum[r][c] > 0xff) hsum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + if(fcs_trgDebug>=2) printf("%5d ",hsum[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + //PRES for QA + if(fcs_trgDebug>0){ + for(int dep=0; dep<6; dep++) { + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1; + } + } + } + } + if(fcs_trgDebug>=2){ + for(int dep=0; dep<6; dep++) { + printf("PRES NS%1d DEP%1d : ",ns,dep); + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1; + printf("%1d", (pres[dep].d[j]>>k)&0x1); + } + printf(" "); + } + printf("\n"); + } + } + + //compute overlapping Ecal 4x4 sums of [15][9] + //take ratio with the closest hcal 4x4 + //u_int esum[15][9]; + //u_int sum[15][9]; + //float ratio[15][9]; + u_int EM1 =0, EM2 =0, EM3=0; + u_int GAM1=0, GAM2=0, GAM3=0; + u_int ELE1=0, ELE2=0, ELE3=0; + u_int HAD1=0, HAD2=0, HAD3=0; + u_int ETOT=0, HTOT=0; + for(int r=0; r<15; r++){ + if(fcs_trgDebug>=2) printf("E4x4 "); + for(int c=0; c<9; c++){ + esum[ns][r][c] + = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]] + + ecal[ETbTdep[r ][c+1]].d[ETbTadr[r ][c+1]] + + ecal[ETbTdep[r+1][c ]].d[ETbTadr[r+1][c ]] + + ecal[ETbTdep[r+1][c+1]].d[ETbTadr[r+1][c+1]]; + //if(esum[r][c] > 0xff) esum[r][c]=0xff; //Tonko says no point to saturate at 8bit here + + // locate the closest hcal + u_int h=hsum[ns][EtoHmap[r][c][0]][EtoHmap[r][c][1]]; + + // locate the max 2x2 hcal + u_int hmax=0; + for(int iz=0; iz<4; iz++){ + int iHCalID = EtoH3map[r][c][iz]; + if(iHCalID < 0) continue; + int irow = iHCalID/5; + int icol = iHCalID%5; + if(hmax < hsum[ns][irow][icol]) hmax = hsum[ns][irow][icol]; + } + + //if(h > 0 || hmax > 0) printf("Checking: %d, %d\n", h, hmax); + + // E+H sum + sum[ns][r][c] = esum[ns][r][c] + h; + + //in VHDL we will do esum>hsum*threshold. Ratio is for human only + if(sum[ns][r][c]==0) { + ratio[ns][r][c]=0.0; + }else{ + ratio[ns][r][c] = float(esum[ns][r][c]) / float(sum[ns][r][c]); + } + + //check EPD hits using the mask + epdcoin[ns][r][c]=0; + for(int dep=0; dep<6; dep++){ + int mask; + if(fcs_readPresMaskFromText==0){ + mask = fcs_ecal_epd_mask[r][c][dep]; //from include file + }else{ + mask = PRES_MASK[r][c][dep]; //from static which was from text file + } + for(int j=0; j<4; j++) { + for(int k=0; k<8; k++){ + if( (mask >> (j*8 + k)) & 0x1) { //if this is 0, don't even put the logic in VHDL + epdcoin[ns][r][c] |= (pres[dep].d[j] >> k) & 0x1; + } + } + } + } + + // integer multiplication as in VHDL! + // ratio thresholds are in fixed point integer where 1.0==128 + u_int h128 = h*128 ; + u_int hmax128 = hmax*128 ; + + if(hmax128 < esum[ns][r][c] * EM_HERATIO_THR){ + if(esum[ns][r][c] > EMTHR1){ + EM1 = 1; + if(epdcoin[ns][r][c]==0) {GAM1 = 1;} + else {ELE1 = 1;} + } + if(esum[ns][r][c] > EMTHR2){ + EM2 = 1; + if(epdcoin[ns][r][c]==0) {GAM2 = 1;} + else {ELE2 = 1;} + } + if(esum[ns][r][c] > EMTHR3){ + EM3 = 1; + if(epdcoin[ns][r][c]==0) {GAM3 = 1;} + else {ELE3 = 1;} + } + } + + if(h128 > esum[ns][r][c] * HAD_HERATIO_THR){ + if(sum[ns][r][c] > HADTHR1) HAD1 = 1; + if(sum[ns][r][c] > HADTHR2) HAD2 = 1; + if(sum[ns][r][c] > HADTHR3) HAD3 = 1; + } + if(fcs_trgDebug>=2) printf("%5d %1d %3.2f ",esum[ns][r][c],epdcoin[ns][r][c],ratio[ns][r][c]); + } + if(fcs_trgDebug>=2) printf("\n"); + } + + //Akio's 6 square JP + int e_col_start[2] = { 0, 4}; //these are 2x2 row/col + int e_col_stop[2] = { 5, 9}; + int e_row_start[3] = { 0, 4, 8}; + int e_row_stop[3] = { 7,11,15}; + int h_col_start[2] = { 0, 2}; + int h_col_stop[2] = { 3, 5}; + int h_row_start[3] = { 0, 2, 5}; + int h_row_stop[3] = { 4, 7, 9}; + int JP1[6] = {0,0,0,0,0,0}; + int JP2[6] = {0,0,0,0,0,0}; + int j=0; + for(int jc=0; jc<2; jc++){ + for(int jr=0; jr<3; jr++){ + jet[ns][j]=0; + for(int c=e_col_start[jc]; c<=e_col_stop[jc]; c++){ + for(int r=e_row_start[jr]; r<=e_row_stop[jr]; r++){ + jet[ns][j] += ecal[ETbTdep[r][c]].d[ETbTadr[r][c]]; + } + } + for(int c=h_col_start[jc]; c<=h_col_stop[jc]; c++){ + for(int r=h_row_start[jr]; r<=h_row_stop[jr]; r++){ + jet[ns][j] += hcal[HTbTdep[r][c]].d[HTbTadr[r][c]]; + } + } + if(jet[ns][j]>0xff) jet[ns][j]=0xff; + if(jet[ns][j]>JETTHR1) JP1[j] = 1; + if(jet[ns][j]>JETTHR2) JP2[j] = 1; + j++; + } + } + if(fcs_trgDebug>=2) printf("JP6 = %3d %3d %3d %3d %3d %3d\n",jet[ns][0],jet[ns][1],jet[ns][2],jet[ns][3],jet[ns][4],jet[ns][5]); + + //Ecal sub-crate sum + u_int esub[4]; + esub[0] = esum[ns][ 0][0]+esum[ns][ 0][2]+esum[ns][ 0][4]+esum[ns][ 0][6]+esum[ns][ 0][8] + + esum[ns][ 2][0]+esum[ns][ 2][2]+esum[ns][ 2][4]+esum[ns][ 2][6]+esum[ns][ 2][8]; + esub[1] = esum[ns][ 4][0]+esum[ns][ 4][2]+esum[ns][ 4][4]+esum[ns][ 4][6]+esum[ns][ 4][8] + + esum[ns][ 6][0]+esum[ns][ 6][2]+esum[ns][ 6][4]+esum[ns][ 6][6]+esum[ns][ 6][8]; + esub[2] = esum[ns][ 8][0]+esum[ns][ 8][2]+esum[ns][ 8][4]+esum[ns][ 8][6]+esum[ns][ 8][8] + + esum[ns][10][0]+esum[ns][10][2]+esum[ns][10][4]+esum[ns][10][6]+esum[ns][10][8]; + esub[3] = esum[ns][12][0]+esum[ns][12][2]+esum[ns][12][4]+esum[ns][12][6]+esum[ns][12][8] + + esum[ns][14][0]+esum[ns][14][2]+esum[ns][14][4]+esum[ns][14][6]+esum[ns][14][8]; + for(int i=0; i<4; i++) if(esub[i]>0xff) esub[i]=0xff; + + //Hcal sub-crate sum + u_int hsub[4]; + hsub[0] = hsum[ns][ 1][0]+hsum[ns][ 1][2]+hsum[ns][ 1][4]; + hsub[1] = hsum[ns][ 3][0]+hsum[ns][ 3][2]+hsum[ns][ 3][4]; + hsub[2] = hsum[ns][ 5][0]+hsum[ns][ 5][2]+hsum[ns][ 5][4]; + hsub[3] = hsum[ns][ 7][0]+hsum[ns][ 7][2]+hsum[ns][ 7][4]; + for(int i=0; i<4; i++) if(hsub[i]>0xff) hsub[i]=0xff; + + //total ET + etot[ns] = esub[0] + esub[1] + esub[2] + esub[3]; + htot[ns] = hsub[0] + hsub[1] + hsub[2] + hsub[3]; + if(etot[ns]>ETOTTHR) ETOT=1; + if(htot[ns]>HTOTTHR) HTOT=1; + if(fcs_trgDebug>=2) printf("E/H Tot = %3d %3d\n",etot[ns],htot[ns]); + + //sending output bits + output[0].d[0] = EM1 + (EM2 <<1) + (EM3 <<2); + output[0].d[1] = ELE1 + (ELE2<<1) + (ELE3<<2); + output[0].d[2] = GAM1 + (GAM2<<1) + (GAM3<<2); + output[0].d[3] = HAD1 + (HAD2<<1) + (HAD3<<2); + output[0].d[4] = (JP1[0] << 0) + (JP1[1]<<1) + (JP1[2]<<2) + (JP1[3]<<3) + (JP1[4]<<4) + (JP1[5]<<5); + output[0].d[5] = ETOT + (HTOT<<1); + output[0].d[6] = (fpre_or<<2) | (hcal_ht<<1) | (ecal_ht); //HT + output[0].d[7] = 0xCD ; + + // upper 8 bits + output[1].d[0] = 0 ; + output[1].d[1] = 0 ; + output[1].d[2] = 0 ; + output[1].d[3] = 0 ; + output[0].d[4] = (JP2[0] << 0) + (JP2[1]<<1) + (JP2[2]<<2) + (JP2[3]<<3) + (JP2[4]<<4) + (JP2[5]<<5); + output[1].d[5] = 0 ; + output[1].d[6] = 0 ; + output[1].d[7] = 0xAB ; + + + if(fcs_trgDebug>=1){ + printf("FCS STG2 NS=%1d output = %02x %02x %02x %02x %02x %02x %02x %02x\n", + ns, + output[0].d[0],output[0].d[1],output[0].d[2],output[0].d[3], + output[0].d[4],output[0].d[5],output[0].d[6],output[0].d[7]); + } + + return ; +} diff --git a/StRoot/RTS/src/TRG_FCS/stage_3_202203.cxx b/StRoot/RTS/src/TRG_FCS/stage_3_202203.cxx index 7fd2303f111..337ae7ce18f 100644 --- a/StRoot/RTS/src/TRG_FCS/stage_3_202203.cxx +++ b/StRoot/RTS/src/TRG_FCS/stage_3_202203.cxx @@ -27,7 +27,8 @@ void fcs_trg_base::stage_3_202203(link_t link[], u_short *dsm_out) if( (link[0].d[2] & 0x01) && (link[2].d[2] & 0x01) ) *dsm_out |= 0x1000; //DiGAM1 FCS12 if( (link[0].d[1] & 0x01) && (link[2].d[1] & 0x01) ) *dsm_out |= 0x2000; //DiELE1 FCS13 if( (link[0].d[6] & 0x04) || (link[2].d[6] & 0x04) ) *dsm_out |= 0x4000; //PresOR FCS14 - *dsm_out |= 0x8000; // always 1 as a marker FCS15 + +// *dsm_out |= 0x8000; // always 1 as a marker FCS15 dsmout = *dsm_out; diff --git a/StRoot/RTS/src/TRG_FCS/stage_3_202207.cxx b/StRoot/RTS/src/TRG_FCS/stage_3_202207.cxx new file mode 100644 index 00000000000..ed246393852 --- /dev/null +++ b/StRoot/RTS/src/TRG_FCS/stage_3_202207.cxx @@ -0,0 +1,60 @@ +#include +#include +#include + +#include "fcs_trg_base.h" + +// And the last stage where North and South are combined. +// For run21, output are 9 bits +// it goes first into the RAT and then to the LastDSM + +void fcs_trg_base::stage_3_202207(link_t link[], u_short *dsm_out) +{ + *dsm_out = 0; + + if( (link[1].d[0] & 0x01) || (link[3].d[0] & 0x01) ) *dsm_out |= 0x1; //HAD0 + if( (link[1].d[0] & 0x02) || (link[3].d[0] & 0x02) ) *dsm_out |= 0x2; //HAD1 + if( (link[1].d[0] & 0x04) || (link[3].d[0] & 0x04) ) *dsm_out |= 0x4; //HAD2 + + if( (link[0].d[0] & 0x01) || (link[2].d[0] & 0x01) ) *dsm_out |= 0x8; //EM0 + if( (link[0].d[0] & 0x02) || (link[2].d[0] & 0x02) ) *dsm_out |= 0x10; //EM1 + if( (link[0].d[0] & 0x04) || (link[2].d[0] & 0x04) ) *dsm_out |= 0x20; //EM2 + + if( (link[0].d[1] & 0x1F) || (link[2].d[1] & 0x1F) ) *dsm_out |= 0x40; //JP2 + + if( (link[1].d[1] & 0x01) || (link[3].d[1] & 0x01) ) *dsm_out |= 0x80; //JPA1 + if( (link[1].d[1] & 0x06) || (link[3].d[1] & 0x06) ) *dsm_out |= 0x100; //JPBC1 + if( (link[1].d[1] & 0x18) || (link[3].d[1] & 0x18) ) *dsm_out |= 0x200; //JPDE1 + + if( (link[0].d[2] & 0x02) || (link[2].d[2] & 0x01) ) *dsm_out |= 0x400; //JPA0 + if( (link[0].d[2] & 0x06) || (link[2].d[2] & 0x06) ) *dsm_out |= 0x800; //JPBC0 + if( (link[0].d[2] & 0x18) || (link[2].d[2] & 0x18) ) *dsm_out |= 0x1000; //JPDE0 + + if( (link[1].d[2] & 0x02) && (link[3].d[2] & 0x1C) ) *dsm_out |= 0x2000; //DiJP + if( (link[1].d[2] & 0x04) && (link[3].d[2] & 0x1A) ) *dsm_out |= 0x2000; //DiJP + if( (link[1].d[2] & 0x18) && (link[3].d[2] & 0x1E) ) *dsm_out |= 0x2000; //DiJP + + if( (link[1].d[2] & 0x02) && (link[2].d[2] & 0x1C) ) *dsm_out |= 0x4000; //DiJPAsy + if( (link[1].d[2] & 0x04) && (link[2].d[2] & 0x1A) ) *dsm_out |= 0x4000; //DiJPAsy + if( (link[1].d[2] & 0x18) && (link[2].d[2] & 0x1E) ) *dsm_out |= 0x4000; //DiJPAsy + if( (link[0].d[2] & 0x02) && (link[3].d[2] & 0x1C) ) *dsm_out |= 0x4000; //DiJPAsy + if( (link[0].d[2] & 0x04) && (link[3].d[2] & 0x1A) ) *dsm_out |= 0x4000; //DiJPAsy + if( (link[0].d[2] & 0x18) && (link[3].d[2] & 0x1E) ) *dsm_out |= 0x4000; //DiJPAsy + + if( (link[0].d[0] & 0x40) && (link[2].d[0] & 0x20) ) *dsm_out |= 0x8000; //DiELEA + if( (link[0].d[0] & 0x20) && (link[2].d[0] & 0x40) ) *dsm_out |= 0x8000; //DiELEA + + dsmout = *dsm_out; + + if(fcs_trgDebug>=1) { + printf("FCS STG3 input 0 = %02x %02x %02x %02x %02x %02x %02x %02x\n", + link[0].d[0],link[0].d[1],link[0].d[2],link[0].d[3], + link[0].d[4],link[0].d[5],link[0].d[6],link[0].d[7]); + printf("FCS STG3 input 1 = %02x %02x %02x %02x %02x %02x %02x %02x\n", + link[2].d[0],link[2].d[1],link[2].d[2],link[2].d[3], + link[2].d[4],link[2].d[5],link[2].d[6],link[2].d[7]); + printf("FCS STG3 output = %04x = ", *dsm_out); + for(int i=7; i>=0; i--){printf("%1d", (dsmout>>i)&0x1);} + printf("\n"); + } +} diff --git a/StRoot/StFcsDbMaker/StFcsDb.cxx b/StRoot/StFcsDbMaker/StFcsDb.cxx index 4bf8b8978b5..2c43d3133a3 100644 --- a/StRoot/StFcsDbMaker/StFcsDb.cxx +++ b/StRoot/StFcsDbMaker/StFcsDb.cxx @@ -301,29 +301,56 @@ int StFcsDb::InitRun(int runNumber) { mRun=runNumber; //storing in DEP sorted table - int ie=0, ih=0, ip=0, ehp, ns, crt, slt, dep, ch; - for(int ins=0; ins=kFcsNDet) return 0.0; - if(id<0 || id>=kFcsMaxId) return 0.0; - return mEtGain[det][id]; + if(id<0 || id>=kFcsMaxId) return 0.0; + return (mEtGain[det][id]-1.0)*factor+1.0; } void StFcsDb::printEtGain(){ @@ -1826,7 +1868,8 @@ void StFcsDb::printEtGain(){ double z=xyz.z(); double l=xyz.mag(); double ptch=gain/l*r; - double ratio=ptch/norm[eh]*1000; + double ratio=1.0; + if(eh<2) ratio=ptch/norm[eh]*1000; //PRES stays 1.0 mEtGain[det][id]=ratio; fprintf(f1,"D=%1d Id=%3d Row=%2d Column=%2d xyz=%7.2f %7.2f %7.2f Gain=%7.5f ET/ch=%6.4f [MeV/count] norm=%6.4f\n", det,id,row,col,x,y,z,gain,ptch*1000,ratio); @@ -1891,15 +1934,14 @@ void StFcsDb::readPedFromText(const char* file){ fclose(F); } -void StFcsDb::readGainFromText(const char* file){ +void StFcsDb::readGainFromText(){ memset(mGain,0,sizeof(mGain)); - LOG_INFO << Form("Reading Gain from %s",file)< +#include + +void fcsGain_db(char* opt = "", char* input) { + gROOT->Macro("LoadLogger.C"); + gSystem->Load("St_base.so"); + gSystem->Load("libStDb_Tables.so"); + gSystem->Load("StDbLib.so"); + + // structure to fill up + fcsEcalGain_st egain; + fcsHcalGain_st hgain; + fcsPresGain_st pgain; + fcsEcalGainCorr_st ecorr; + fcsHcalGainCorr_st hcorr; + fcsPresValley_st pcorr; + + TString option(opt); + std::cout << "Opt =" << opt << "\n"; + std::cout << "writedb = " << option.Contains("writedb") << "\n"; + std::cout << "ecal = " << option.Contains("ecal") << "\n"; + std::cout << "hcal = " << option.Contains("hcal") << "\n"; + std::cout << "pres = " << option.Contains("pres") << "\n"; + std::cout << "ehp = " << option.Contains("ehp") << "\n"; + std::cout << "gain = " << option.Contains("gain") << "\n"; + std::cout << "corr = " << option.Contains("corr") << "\n"; + std::cout << "both = " << option.Contains("both") << "\n"; + + int ecal=0, hcal=0, pres=0, gain=0, corr=0; + if(option.Contains("ecal") || option.Contains("ehp")) ecal=1; + if(option.Contains("hcal") || option.Contains("ehp")) hcal=1; + if(option.Contains("pres") || option.Contains("ehp")) pres=1; + if(option.Contains("gain") || option.Contains("both")) gain=1; + if(option.Contains("corr") || option.Contains("both")) corr=1; + + TString data(input); + TString storeTime; + TString flavor; + if(data.Contains("run22sim")){ + storeTime = "2021-10-15 00:00:00"; flavor="sim"; + if(ecal && gain) for(int i=0; i<1496; i++) egain.gain[i]=0.0053; //default 5.3MeV/ch + if(hcal && gain) for(int i=0; i< 520; i++) hgain.gain[i]=0.0053; //default 5.3MeV/ch + if(pres && gain) for(int i=0; i< 384; i++) pgain.gain[i]=0.01; //100ch for MIP + if(ecal && corr) for(int i=0; i<1496; i++) ecorr.gaincorr[i]=1.0;//default 1 + if(hcal && corr) for(int i=0; i< 520; i++) hcorr.gaincorr[i]=1.0;//default 1 + if(pres && corr) for(int i=0; i< 384; i++) pcorr.valley[i]=0.5; //0.5 for 1/2 MIP + } + else if(data.Contains("run22ofl")){ + storeTime = "2021-10-25 00:00:00"; flavor="ofl"; + if(ecal && gain) for(int i=0; i<1496; i++) egain.gain[i]=0.0053; //default 5.3MeV/ch + if(hcal && gain) for(int i=0; i< 520; i++) hgain.gain[i]=0.00265; //We found hcal has 1/2 gain + if(pres && gain) for(int i=0; i< 384; i++) pgain.gain[i]=0.01; //100ch for MIP + if(ecal && corr) for(int i=0; i<1496; i++) ecorr.gaincorr[i]=1.0; //default 1 + if(hcal && corr) for(int i=0; i< 520; i++) hcorr.gaincorr[i]=1.0; //default 1 + if(pres && corr) for(int i=0; i< 384; i++) pcorr.valley[i]=0.5; //0.5 for 1/2 MIP + } + else{ + std::cout<<"Invalid year range"<Setenv("DB_ACCESS_MODE","write"); + cout << "DB_ACCESS_MODE="<Getenv("DB_ACCESS_MODE")<initConfig("Calibrations_fcs"); + mgr->setStoreTime(storeTime.Data()); + if(ecal && gain){ + StDbTable* table = node->addDbTable("fcsEcalGain"); + table->SetTable((char*)&egain,1); + table->setFlavor(flavor.Data()); + mgr->storeDbTable(table); + } + if(hcal && gain){ + StDbTable* table = node->addDbTable("fcsHcalGain"); + table->SetTable((char*)&hgain,1); + table->setFlavor(flavor.Data()); + mgr->storeDbTable(table); + } + if(pres && gain){ + StDbTable* table = node->addDbTable("fcsPresGain"); + table->SetTable((char*)&pgain,1); + table->setFlavor(flavor.Data()); + mgr->storeDbTable(table); + } + if(ecal && corr){ + StDbTable* table = node->addDbTable("fcsEcalGainCorr"); + table->SetTable((char*)&ecorr,1); + table->setFlavor(flavor.Data()); + mgr->storeDbTable(table); + } + if(hcal && corr){ + StDbTable* table = node->addDbTable("fcsHcalGainCorr"); + table->SetTable((char*)&hcorr,1); + table->setFlavor(flavor.Data()); + mgr->storeDbTable(table); + } + if(pres && corr){ + StDbTable* table = node->addDbTable("fcsPresValley"); + table->SetTable((char*)&pcorr,1); + table->setFlavor(flavor.Data()); + mgr->storeDbTable(table); + } + gSystem->Unsetenv("DB_ACCESS_MODE"); + std::cout << "Done with database upload \n"; + } + + gSystem->Load("StChain"); + gSystem->Load("StBFChain"); + gSystem->Load("StUtilities"); + gSystem->Load("StIOMaker"); + gSystem->Load("StarClassLibrary"); + gSystem->Load("St_Tables"); + gSystem->Load("StDbLib"); + gSystem->Load("StDbBroker"); + gSystem->Load("St_db_Maker"); + + int date,time,from=0,n=0; + TString datetime(storeTime),token; + datetime.ReplaceAll("-",""); + datetime.ReplaceAll(":",""); + while(datetime.Tokenize(token,from," ")){ + if(n==0) date=atoi(token.Data()); + if(n==1) time=atoi(token.Data()); + n++; + } + std::cout << "Readout time="<SetDebug(); + dbMk->SetDateTime(date,time); + dbMk->SetFlavor(flavor.Data()); + dbMk->Init(); + dbMk->Make(); + + TDataSet *DB = 0; + DB = dbMk->GetInputDB("Calibrations/fcs"); + if(!DB){std::cout << "ERROR: no db maker or Calibrations/fcs" << std::endl; } + if(ecal && gain){ + St_fcsEcalGain *dbTable_eg = (St_fcsEcalGain*) DB->Find("fcsEcalGain"); + if(dbTable_eg){ + std::cout << "Reading fcsEcalGain table from DB\n"; + fcsEcalGain_st *dbSt_eg = dbTable_eg->GetTable(); + Int_t rows = dbTable_eg->GetNRows(); + for(int i=0; iFind("fcsHcalGain"); + if(dbTable_hg){ + std::cout << "Reading fcsHcalGain table from DB\n"; + fcsHcalGain_st *dbSt_hg = dbTable_hg->GetTable(); + Int_t rows = dbTable_hg->GetNRows(); + for(int i=0; iFind("fcsPresGain"); + if(dbTable_pg){ + std::cout << "Reading fcsPresGain table from DB\n"; + fcsPresGain_st *dbSt_pg = dbTable_pg->GetTable(); + Int_t rows = dbTable_pg->GetNRows(); + for(int i=0; iFind("fcsEcalGainCorr"); + if(dbTable_ec){ + std::cout << "Reading fcsEcalGainCorr table from DB\n"; + fcsEcalGainCorr_st *dbSt_ec = dbTable_ec->GetTable(); + Int_t rows = dbTable_ec->GetNRows(); + for(int i=0; iFind("fcsHcalGainCorr"); + if(dbTable_hc){ + std::cout << "Reading fcsHcalGainCorr table from DB\n"; + fcsHcalGainCorr_st *dbSt_hc = dbTable_hc->GetTable(); + Int_t rows = dbTable_hc->GetNRows(); + for(int i=0; iFind("fcsPresValley"); + if(dbTable_pc){ + std::cout << "Reading fcsPresValley table from DB\n"; + fcsPresValley_st *dbSt_pc = dbTable_pc->GetTable(); + Int_t rows = dbTable_pc->GetNRows(); + for(int i=0; iGet("FcsTrgRate"); + float tot=h->GetBinContent(mNTRG+1); + float bbc=5.0e6; + int daq=0; + printf("Total %d events\n",(int)tot); + printf("TRG N Rate[Hz]@5MHzBBC DaqRate PS\n"); + for(int i=0; iGetBinContent(i+1); + float rate=n/tot*bbc; + int ps=rate/bw[i]; + if(ps<1) ps=1; + daq+=bw[i]; + printf("%8s %9d %10.1f %4d %6d\n", + ctrg[i],(int)n,rate,bw[i],ps); + } + printf("\n"); + printf("\n"); + printf("\n",tot,bbc,daq); + for(int i=0; iGetBinContent(i+1); + float rate=n/tot*bbc; + int ps=rate/bw[i]; + printf("\n", + i,ctrg[i],cthr[i],(int)n,(int)rate,bw[i],ps); + } + printf("
#TRGE ThreNScalerRate[Hz]@5MHzBBCDaqRate[Hz]PS
- Total-%7d%7d%7d-
%2d%10s%10s%7d%7d%7d%7d
\n"); +} diff --git a/StRoot/StFcsFastSimulatorMaker/macro/runSimBfc.C b/StRoot/StFcsFastSimulatorMaker/macro/runSimBfc.C index 284f743f9d2..727f5642a36 100644 --- a/StRoot/StFcsFastSimulatorMaker/macro/runSimBfc.C +++ b/StRoot/StFcsFastSimulatorMaker/macro/runSimBfc.C @@ -1,14 +1,15 @@ TString input_dir = "./"; TString output_dir = "./"; //TString input_chain = "sdt20161210.120000,fzin,geant,evout,y2015,FieldOn,logger,MakeEvent,McEvout,IdTruth,ReverseField,db,fcsSim,fcsCluster,fcsPoint,-tpcDB"; -TString input_chain = "fzin,geant,FieldOn,logger,MakeEvent,fcsSim,fcsWFF,fcsCluster,fcsPoint"; +TString input_chain = "sdt20211025.120000,fzin,geant,FieldOn,logger,MakeEvent,fcsSim,fcsWFF,fcsCluster,fcsPoint"; class StFmsSimulatorMaker; -void runSimBfc( Int_t nEvents=1000, Int_t run=1, const char* pid="ele", int e=0, float pt=1.5, float vz=0.0, +void runSimBfc( Int_t nEvents=1000, Int_t run=1, const char* pid="jet", int TrgVersion=202207, + int debug=0, int e=0, float pt=1.5, float vz=0.0, char* epdmask="0.0100", int leakyHcal=0, - int eventDisplay=1, + int eventDisplay=0, TString myDir=input_dir, TString myOutDir=output_dir, TString myChain=input_chain, Int_t mnEvents=0){ @@ -61,7 +62,8 @@ void runSimBfc( Int_t nEvents=1000, Int_t run=1, const char* pid="ele", int e=0, StFcsFastSimulatorMaker *fcssim = (StFcsFastSimulatorMaker*) chain->GetMaker("fcsSim"); fcssim->setDebug(1); fcssim->setLeakyHcal(leakyHcal); - + + /* StFcsWaveformFitMaker *wff=(StFcsWaveformFitMaker *)chain->GetMaker("StFcsWaveformFitMaker"); wff->setDebug(1); wff->setEnergySelect(0); @@ -72,16 +74,22 @@ void runSimBfc( Int_t nEvents=1000, Int_t run=1, const char* pid="ele", int e=0, StFcsPointMaker *poi=(StFcsPointMaker *)chain->GetMaker("StFcsPointMaker"); poi->setDebug(1); poi->setShowerShape(3); + */ gSystem->Load("RTS"); gSystem->Load("StFcsTriggerSimMaker"); StFcsTriggerSimMaker* fcsTrgSim = new StFcsTriggerSimMaker(); - fcsTrgSim->setTrigger(202201); - fcsTrgSim->setDebug(3); - TString txfile(outfile); txfile.ReplaceAll(".root",".event.txt"); fcsTrgSim->setWriteEventText(txfile.Data()); - TString qafile(outfile); qafile.ReplaceAll(".root",Form(".thr%s.trgflt.root",epdmask)); fcsTrgSim->setWriteQaFile(qafile.Data()); - fcsTrgSim->setReadPresMask(Form("mask/fcs_ecal_epd_mask.ele.pt0.6.vz0.thr%s.txt",epdmask)); - + fcsTrgSim->setSimMode(1); + fcsTrgSim->setTrigger(TrgVersion); + fcsTrgSim->setDebug(debug); + fcsTrgSim->setEtGain(1.0); //ET match + //fcsTrgSim->setEtGain(0.5); //halfway + //fcsTrgSim->setEtGain(0.0); //E match + //fcsTrgSim->setReadPresMask(Form("mask/fcs_ecal_epd_mask.ele.pt0.6.vz0.thr%s.txt",epdmask)); + //TString txfile(outfile); txfile.ReplaceAll(".root",".event.txt"); fcsTrgSim->setWriteEventText(txfile.Data()); + TString qafile(outfile); qafile.ReplaceAll(".root",".qahist.root"); fcsTrgSim->setWriteQaHist(qafile.Data()); + fcsTrgSim->setThresholdFile("stage_params.txt"); + gSystem->Load("StFcsTrgQaMaker"); StFcsTrgQaMaker* fcsTrgQa = new StFcsTrgQaMaker(); TString tqafile(outfile); tqafile.ReplaceAll(".root",Form(".thr%s.trgqa.root",epdmask)); diff --git a/StRoot/StFcsFastSimulatorMaker/macro/runpythia b/StRoot/StFcsFastSimulatorMaker/macro/runpythia index 0c34d0e5b21..0872b8be7c7 100755 --- a/StRoot/StFcsFastSimulatorMaker/macro/runpythia +++ b/StRoot/StFcsFastSimulatorMaker/macro/runpythia @@ -4,10 +4,11 @@ set run=$2 set particle=$3 set vz=$4 set epdmask=$5 -set outdir=$6 -set nogeant=$7 +set indir=$6 +set outdir=$7 +set nogeant=$8 -echo nev=$nev run=$run particle=$particle epdmask=$epdmask outdir=$outdir nogeant=$nogeant +echo nev=$nev run=$run particle=$particle epdmask=$epdmask indir=$indir outdir=$outdir nogeant=$nogeant stardev set dir=$cwd @@ -55,26 +56,30 @@ if( ! -e mask ) then ln -s $dir/mask endif +if( ! -e stage_params.txt ) then + ln -s $dir/stage_params.txt +endif + pwd ls -ltra -set name=pythia.$particle.vz$vz.run$run +set name=pythia_${particle}_vz${vz}_run${run} echo name=$name if ( $nogeant == 0 ) then echo root4star -b -q 'runPythia.C('$nev','$run',"'$particle'",'$vz')' root4star -b -q 'runPythia.C('$nev','$run',"'$particle'",'$vz')' else - echo /bin/cp $dir/$outdir/$name.fzd $tmpdir/ - /bin/cp $dir/$outdir/$name.fzd $tmpdir/ + echo /bin/cp $dir/$indir/$name.fzd $tmpdir/ + /bin/cp $dir/$indir/$name.fzd $tmpdir/ endif -echo root4star -b -q 'runSimBfc.C('$nev','$run',"'$particle'",0.0,0.0,'$vz',"'$epdmask'")' -root4star -b -q 'runSimBfc.C('$nev','$run',"'$particle'",0.0,0.0,'$vz',"'$epdmask'")' +echo root4star -b -q 'runSimBfc.C('$nev','$run',"'$particle'",202207,0,0,0.0,'$vz',"'$epdmask'")' +root4star -b -q 'runSimBfc.C('$nev','$run',"'$particle'",202207,0,0,0.0,'$vz',"'$epdmask'")' echo moving $tmpdir/$name to $dir/$outdir/ ls -ltra $name.* -/bin/mv $name.* $dir/$outdir/ +/bin/mv $name.qahist.root $dir/$outdir/ #/bin/rm {$name}.* diff --git a/StRoot/StFcsFastSimulatorMaker/macro/stage_params.txt b/StRoot/StFcsFastSimulatorMaker/macro/stage_params.txt new file mode 100644 index 00000000000..cc205933ab8 --- /dev/null +++ b/StRoot/StFcsFastSimulatorMaker/macro/stage_params.txt @@ -0,0 +1,27 @@ +40 10 0 FCS_PHTTHR 100 +40 10 1 FCS_EM-HERATIO-THR 32 +40 10 2 FCS_HAD-HERATIO-THR 32 +40 10 3 FCS_EMTHR2 158 +40 10 4 FCS_EMTHR1 111 +40 10 5 FCS_EMTHR0 63 +40 10 6 FCS_ELETHR2 32 +40 10 7 FCS_ELETHR1 22 +40 10 8 FCS_ELETHR0 25 +40 10 9 FCS_HADTHR2 190 +40 10 10 FCS_HADTHR1 127 +40 10 11 FCS_HADTHR0 63 +40 10 12 FCS_JPATHR2 253 +40 10 13 FCS_JPATHR1 190 +40 10 14 FCS_JPATHR0 127 +40 10 15 FCS_JPBCTHR2 253 +40 10 16 FCS_JPBCTHR1 190 +40 10 17 FCS_JPBCTHR0 127 +40 10 18 FCS_JPBCTHRD 158 +40 10 19 FCS_JPDETHR2 253 +40 10 20 FCS_JPDETHR1 190 +40 10 21 FCS_JPDETHR0 127 +40 10 22 FCS_JPDETHRD 158 +40 10 23 FCS_EHTTHR 32 +40 10 24 FCS_HHTTHR 32 +40 10 25 FCS_ETOTTHR 50 +40 10 26 FCS_HTOTTHR 50 diff --git a/StRoot/StFcsFastSimulatorMaker/macro/submitpythia.pl b/StRoot/StFcsFastSimulatorMaker/macro/submitpythia.pl index 0dd63f7cf28..0d7a42526ab 100755 --- a/StRoot/StFcsFastSimulatorMaker/macro/submitpythia.pl +++ b/StRoot/StFcsFastSimulatorMaker/macro/submitpythia.pl @@ -1,18 +1,15 @@ #!/usr/bin/perl -w -@pid = ("dy","dybg"); +#@pid = ("dy","dybg"); +@pid = ("jet"); @vz = ("0"); -$outdir="out"; -$nev = 500; +$indir="DATA_OUT"; +$outdir="fcsMc"; +$nev = 1000; $run1= 1; -$run2= 200; +$run2= 2000; -#@mask = ("0.0300"); -#$nogeant=0; - -@mask = ("0.0010"); -#@mask = ("0.3000","0.1000", "0.0100","0.0030","0.0010"); -#@mask = ("0.3000","0.1000","0.0300","0.0100","0.0030","0.0010"); +@mask = ("0.0300"); $nogeant=1; my $opt="none"; @@ -26,8 +23,10 @@ my $exe="runpythia"; my $condordir="condor"; my $cwd=$ENV{'PWD'}; +my $logdir="$outdir/log"; if (! -e "$outdir") {system("/bin/mkdir $outdir");} +if (! -e "$logdir") {system("/bin/mkdir $logdir");} if (! -e "$condordir") {system("/bin/mkdir $condordir");} my $condor="$condordir/submit_pythia.txt"; if (-e $condor) {system("/bin/rm $condor");} @@ -37,9 +36,7 @@ print(OUT "Universe = vanilla\n"); print(OUT "notification = never\n"); print(OUT "getenv = True\n"); -print(OUT "Requirements = CPU_Experiment == \"star\"\n"); -print(OUT "+Experiment = \"star\"\n"); -print(OUT "+Job_Type = \"cas\"\n"); +print(OUT "Accounting_group = group_star.cas\n"); print(OUT "\n"); $njob=0; @@ -49,12 +46,11 @@ for($r=$run1; $r<=$run2; $r++){ $name="pythia.$p.vz$vz"; $out="$outdir/$name"; - $logdir="$out/log"; $log="$cwd/$logdir/$name.run$r.log"; if (! -e "$cwd/$out") {system("/bin/mkdir $cwd/$out");} if (! -e "$cwd/$logdir") {system("/bin/mkdir $cwd/$logdir");} - print(OUT "Arguments = \"$nev $r $p $vz $m $out $nogeant\"\n"); + print(OUT "Arguments = \"$nev $r $p $vz $m $indir $out $nogeant\"\n"); print(OUT "Log = $log\n"); print(OUT "Output = $log\n"); print(OUT "Error = $log\n"); diff --git a/StRoot/StFcsFastSimulatorMaker/macro/thresh.pl b/StRoot/StFcsFastSimulatorMaker/macro/thresh.pl new file mode 100755 index 00000000000..3c09adb76e9 --- /dev/null +++ b/StRoot/StFcsFastSimulatorMaker/macro/thresh.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl +# +# Server and Port depend on run year: +# Year : ongoing onldb:3501 +# 20xx onlsun1:3400+x-1 + +if (@ARGV != 1) { + printf("thresh.pl run\n"); + exit(0); +} + +$run = @ARGV[0]; +$year = $run/1000000; + +if($run > 22274000){ + $server = "onldb.starp.bnl.gov"; + $port = 3501; +}else{ + $server = "onlsun1.starp.bnl.gov"; + $port = 3400+$year-1; +} + +$query = "select dictHash from run where idx_rn=$run"; +$hash = `mysql -h $server --port=$port Conditions_rts -s -e "$query"`; +#printf "hash=$hash"; + +sub get { + $thresh = $_[0]; + $query = "select distinct object from dict where hash=$hash and label='$thresh'"; + $obj = `mysql -h $server --port=$port Conditions_rts -s -e "$query"`; + $query = "select distinct idx from dict where hash=$hash and label='$thresh'"; + $idx = `mysql -h $server --port=$port Conditions_rts -s -e "$query"`; + $query = "select distinct reg from dict where hash=$hash and label='$thresh'"; + $reg = `mysql -h $server --port=$port Conditions_rts -s -e "$query"`; + $query = "select distinct value from dict where hash=$hash and label='$thresh'"; + $value = `mysql -h $server --port=$port Conditions_rts -s -e "$query"`; + $query = "select distinct defaultvalue from dict where hash=$hash and label='$thresh'"; + $dfault = `mysql -h $server --port=$port Conditions_rts -s -e "$query"`; + chomp $value; chomp $idx; chomp $obj; chomp $dfault; chomp $reg; + $v = $value; + if ($v eq -1) {$v = $dfault;} + printf("%s %s %s %s %s %s \n",$obj,$idx,$reg,$thresh,$v); +} + +&get("FCS_PHTTHR"); +&get("FCS_EM-HERATIO-THR"); +&get("FCS_HAD-HERATIO-THR"); +&get("FCS_EMTHR2"); +&get("FCS_EMTHR1"); +&get("FCS_EMTHR0"); +&get("FCS_ELETHR2"); +&get("FCS_ELETHR1"); +&get("FCS_ELETHR0"); +&get("FCS_HADTHR2"); +&get("FCS_HADTHR1"); +&get("FCS_HADTHR0"); +&get("FCS_JPATHR2"); +&get("FCS_JPATHR1"); +&get("FCS_JPATHR0"); +&get("FCS_JPBCTHR2"); +&get("FCS_JPBCTHR1"); +&get("FCS_JPBCTHR0"); +&get("FCS_JPBCTHRD"); +&get("FCS_JPDETHR2"); +&get("FCS_JPDETHR1"); +&get("FCS_JPDETHR0"); +&get("FCS_JPDETHRD"); +&get("FCS_EHTTHR"); +&get("FCS_HHTTHR"); +&get("FCS_ETOTTHR"); +&get("FCS_HTOTTHR"); diff --git a/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.cxx b/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.cxx index cf039002424..f0c52117066 100644 --- a/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.cxx +++ b/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.cxx @@ -76,6 +76,8 @@ ClassImp(StFcsWaveformFitMaker) #include #include "TMath.h" #include "TF1.h" +#include "TH1F.h" +#include "TH2F.h" #include "TGraph.h" #include "TGraphAsymmErrors.h" #include "TGraphAsymmErrorsWithReset.h" @@ -154,7 +156,13 @@ int StFcsWaveformFitMaker::InitRun(int runNumber) { if(mMeasureTime){ mTime=new TH1F("FitTime","FitTime; msec",200,0,6); } - + if(mFilter && mFilter[0]=='0'){ + mTimeIntg[0]=new TH2F("Noboth", "No both; PeakTB; Integral",100,47.0,54.0,400,0.0,2000); + mTimeIntg[1]=new TH2F("NoFall", "No Fall; PeakTB; Integral",100,47.0,54.0,400,0.0,2000); + mTimeIntg[2]=new TH2F("NoRise", "No Rise; PeakTB; Integral",100,47.0,54.0,400,0.0,2000); + mTimeIntg[3]=new TH2F("Accepted","Accepted; PeakTB; Integral",100,47.0,54.0,400,0.0,2000); + } + if(mTail==1){ GSigma = GSigma_1; A1 = A1_1; @@ -195,6 +203,17 @@ int StFcsWaveformFitMaker::Finish(){ mTime->Draw(); c->SaveAs(mMeasureTime); } + if(mFilter && mFilter[0]=='0'){ + TCanvas *c= new TCanvas("Stage0","Stage0",10,10,800,800); + gStyle->SetOptStat(111110); + gStyle->SetLabelSize(0.02,"xy"); + c->Divide(2,2); + c->cd(1)->SetLogy(); mTimeIntg[0]->Draw("colz"); + c->cd(2)->SetLogy(); mTimeIntg[1]->Draw("colz"); + c->cd(3)->SetLogy(); mTimeIntg[2]->Draw("colz"); + c->cd(4)->SetLogy(); mTimeIntg[3]->Draw("colz"); + c->SaveAs("stage0.png"); + } return kStOK; } @@ -319,7 +338,7 @@ TGraphAsymmErrors* StFcsWaveformFitMaker::makeTGraphAsymmErrors(TH1* hist){ } TGraphAsymmErrors* StFcsWaveformFitMaker::makeTGraphAsymmErrors(StFcsHit* hit){ - int N = mMaxTB - mMinTB +1; + //int N = mMaxTB - mMinTB +1; int n = hit->nTimeBin(); TGraphAsymmErrors* gae = resetGraph(); mDb->getName(hit->detectorId(),hit->id(),mDetName); @@ -357,8 +376,43 @@ float StFcsWaveformFitMaker::analyzeWaveform(int select, TGraphAsymmErrors* g, f LOG_WARN << "Unknown fit/sum method select=" << select << endm; } //if(func && (mFitDrawOn || mFilter ) && mFilename && mPage<=mMaxPage) drawFit(g,func); - int flag=0; - if(mFilter){ + int flag=1; + if(mFilter && mFilter[0]=='0'){ + flag=0; + if(integral>0 && res[2]>47.0 && res[2]<54.0){ + int peak=0; + double* t=g->GetX(); + double* a=g->GetY(); + for(int i=0; iGetN()-1; i++){ + int t0=t[i]; + int t1=t[i+1]; + int a0=a[i]; + int a1=a[i+1]; + int dt=t1-t0; + int da=a1-a0; + if(GetDebug()) printf("AAA t0=%4d t1=%4d a0=%4d a1=%4d dt=%4d da=%5d ",t0,t1,a0,a1,dt,da); + if(t0==mCenterTB-3 && dt==1){ + if(da>0) { + peak+=1; + if(GetDebug()) printf("R"); + } + else {if(GetDebug()) printf("X");} + } + if(t0==mCenterTB+3 && dt==1){ + if(da<0) { + peak+=2; + if(GetDebug()) printf("F"); + } + else {if(GetDebug()) printf("X");} + } + if(GetDebug()) printf("\n"); + } + printf("BBB Intg=%8.2f peak=%6.2f Raise/Fall=%1d\n",integral,res[2],peak); + if(peak<3 && integral>50 && res[2]>49) flag=1; + mTimeIntg[peak]->Fill(res[2],integral); + } + }else if(mFilter){ + flag=0; TString dname(mDetName); if(integral>50 && dname.Contains(mFilter)) flag=1; } diff --git a/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.h b/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.h index 3f4cb6df5b2..346f59f6bc6 100644 --- a/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.h +++ b/StRoot/StFcsWaveformFitMaker/StFcsWaveformFitMaker.h @@ -60,6 +60,8 @@ class StFcsDb; class TGraphAsymmErrors; class TGraph; class TCanvas; +class TH1F; +class TH2F; class StFcsWaveformFitMaker : public StMaker { public: @@ -96,6 +98,9 @@ class StFcsWaveformFitMaker : public StMaker { void setMeasureTime(char* file) {mMeasureTime=file;} TH1F* mTime; + //stage0 peak algo study + TH2F* mTimeIntg[4]; + //create makeTGraphAsymmErrors from given timebin and adc data //with asymmetroc errors when adc is saturated //Places graph at index 0 of internal TClonesArray and will be deleted in destructor diff --git a/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.cxx b/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.cxx index 02aa06d715b..8496d2dfb3d 100644 --- a/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.cxx +++ b/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.cxx @@ -56,6 +56,15 @@ namespace { float fcs_trg_pt_correction[kMaxNS][kMaxDet][kMaxDep][kMaxCh]; float fcs_trg_gain_correction[kMaxNS][kMaxDet][kMaxDep][kMaxCh]; u_short fcs_trg_pedestal[kMaxNS][kMaxDet][kMaxDep][kMaxCh] ; + + static const int mNTRG=21; + static const char* ctrg[mNTRG]={"JP2", "JPA1", "JPA0", "JPBC1", "JPBC0", "JPDE1", "JPDE0", + "DiJP", "DiJPAsy", + "DY","JPsi","DYNoEpd","DYAsy", + "Had2","Had1","Had0", + "EM2","EM1","EM0", + "ELE2","EM3"}; + int NTRG[mNTRG+1]; } ClassImp(StFcsTriggerSimMaker); @@ -97,81 +106,37 @@ int StFcsTriggerSimMaker::Init(){ mTrgSim->stage_version[1]=1; mTrgSim->stage_version[2]=3; mTrgSim->stage_version[3]=3; - //Thresholds - mTrgSim->EM_HERATIO_THR = 32; - mTrgSim->HAD_HERATIO_THR = 32; - if(0){ - mTrgSim->EMTHR1 = 32; - mTrgSim->EMTHR2 = 48; - mTrgSim->EMTHR3 = 64; - mTrgSim->HADTHR1 = 32; - mTrgSim->HADTHR2 = 48; - mTrgSim->HADTHR3 = 64; - mTrgSim->JETTHR1 = 64; - mTrgSim->JETTHR2 = 128; - mTrgSim->ETOTTHR = 128; - mTrgSim->HTOTTHR = 64; - mTrgSim->EHTTHR = 16; - mTrgSim->HHTTHR = 16; - } - if(0){ - mTrgSim->EMTHR1 = 64; - mTrgSim->EMTHR2 = 128; - mTrgSim->EMTHR3 = 192; - mTrgSim->HADTHR1 = 64; - mTrgSim->HADTHR2 = 128; - mTrgSim->HADTHR3 = 192; - mTrgSim->JETTHR1 = 128; - mTrgSim->JETTHR2 = 192; - mTrgSim->ETOTTHR = 192; - mTrgSim->HTOTTHR = 64; - mTrgSim->EHTTHR = 64; - mTrgSim->HHTTHR = 16; - } - if(0){ - mTrgSim->EMTHR1 = 180; - mTrgSim->EMTHR2 = 240; - mTrgSim->EMTHR3 = 250; - mTrgSim->HADTHR1 = 180; - mTrgSim->HADTHR2 = 240; - mTrgSim->HADTHR3 = 250; - mTrgSim->JETTHR1 = 150; - mTrgSim->JETTHR2 = 250; - mTrgSim->ETOTTHR = 250; - mTrgSim->HTOTTHR = 150; - mTrgSim->EHTTHR = 200; - mTrgSim->HHTTHR = 40; - } - if(0){ - mTrgSim->EMTHR1 = 70; - mTrgSim->EMTHR2 = 120; - mTrgSim->EMTHR3 = 160; - mTrgSim->HADTHR1 = 85; - mTrgSim->HADTHR2 = 130; - mTrgSim->HADTHR3 = 160; - mTrgSim->JETTHR1 = 240; - mTrgSim->JETTHR2 = 250; - mTrgSim->ETOTTHR = 250; - mTrgSim->HTOTTHR = 230; - mTrgSim->EHTTHR = 80; - mTrgSim->HHTTHR = 70; - } - if(1){ - mTrgSim->EMTHR1 = 70; - mTrgSim->EMTHR2 = 50; - mTrgSim->EMTHR3 = 160; - mTrgSim->HADTHR1 = 85; - mTrgSim->HADTHR2 = 50; - mTrgSim->HADTHR3 = 160; - mTrgSim->JETTHR1 = 240; - mTrgSim->JETTHR2 = 250; - mTrgSim->ETOTTHR = 100; - mTrgSim->HTOTTHR = 80; - mTrgSim->EHTTHR = 80; - mTrgSim->HHTTHR = 70; - } - mTrgSim->PHTTHR = 160; + }else if(mTrgSelect==202204){ + mTrgSim->stage_version[0]=2; + mTrgSim->stage_version[1]=1; + mTrgSim->stage_version[2]=4; + mTrgSim->stage_version[3]=3; + }else if(mTrgSelect==202205){ + mTrgSim->stage_version[0]=2; + mTrgSim->stage_version[1]=1; + mTrgSim->stage_version[2]=5; + mTrgSim->stage_version[3]=3; + }else if(mTrgSelect==202206){ + mTrgSim->stage_version[0]=2; + mTrgSim->stage_version[1]=1; + mTrgSim->stage_version[2]=6; + mTrgSim->stage_version[3]=3; + }else if(mTrgSelect==202207){ + mTrgSim->stage_version[0]=2; + mTrgSim->stage_version[1]=1; + mTrgSim->stage_version[2]=7; + mTrgSim->stage_version[3]=7; + } + + //Thresholds + if(mThresholdFile){ + readThresholdFile(); + }else if(mThresholdDb){ + readThresholdDb(); } + //mTrgSim->EM_HERATIO_THR = 32; + //mTrgSim->HAD_HERATIO_THR = 32; + //EPD mask if(mPresMask){ printf("Reading PresMask from %s\n",mPresMask); @@ -193,6 +158,8 @@ int StFcsTriggerSimMaker::Init(){ mTrgSim->fcs_readPresMaskFromText=1; } } + + memset(NTRG,0,sizeof(NTRG)); return kStOK; } @@ -205,12 +172,16 @@ int StFcsTriggerSimMaker::InitRun(int runNumber){ } //QA root file - if(mQaFilename){ - mQaFile=new TFile(mQaFilename,"RECREATE"); + if(mQaTreeFilename){ + mQaTreeFile=new TFile(mQaTreeFilename,"RECREATE"); mTree = new TTree("trgsim","trigger sim QA"); mTree->Branch("flt",&mFlt,"flt/I"); mTree->Branch("trg",&mTrg,"trg/I"); } + if(mQaHistFilename){ + mQaHistFile=new TFile(mQaHistFilename,"RECREATE"); + mTrgRate = new TH1F("FcsTrgRate","FcsTrgRate",mNTRG+1,0,mNTRG+1); + } //Write Text event file & gainfile FILE* gainfile=0; @@ -227,8 +198,13 @@ int StFcsTriggerSimMaker::InitRun(int runNumber){ for(int id=0; idgetDepfromId(det,id,ehp,ns,crt,sub,dep,ch); - fcs_trg_pt_correction[ns][ehp][dep][ch] = mFcsDb->getEtGain(det,id); - fcs_trg_gain_correction[ns][ehp][dep][ch] = mFcsDb->getGainCorrection(det,id); + if(det<4){ + fcs_trg_pt_correction[ns][ehp][dep][ch] = mFcsDb->getEtGain(det,id,mEtFactor); + fcs_trg_gain_correction[ns][ehp][dep][ch] = mFcsDb->getGainCorrection(det,id); + }else{ + fcs_trg_pt_correction[ns][ehp][dep][ch] = 1.0; + fcs_trg_gain_correction[ns][ehp][dep][ch] = 1.0; + } fcs_trg_pedestal[ns][ehp][dep][ch] = 0; mTrgSim->p_g[ns][ehp][dep][ch].ped = fcs_trg_pedestal[ns][ehp][dep][ch]; @@ -240,7 +216,7 @@ int StFcsTriggerSimMaker::InitRun(int runNumber){ mTrgSim->p_g[ns][ehp][dep][ch].gain = g; /* - printf("AAA %1d %1d %2d %2d pT=%6.3f corr=%6.3f ped=%4d\n",ns,ehp,dep,ch, + printf("AAAGAIN %1d %1d %2d %2d pT=%6.3f corr=%6.3f ped=%4d\n",ns,ehp,dep,ch, fcs_trg_pt_correction[ns][ehp][dep][ch], fcs_trg_gain_correction[ns][ehp][dep][ch], fcs_trg_pedestal[ns][ehp][dep][ch]); @@ -265,11 +241,22 @@ int StFcsTriggerSimMaker::Finish(){ printf("Closing %s\n",mFilename); fclose(mFile); } - if(mQaFile){ - printf("Closing %s\n",mQaFilename); + if(mQaTreeFile){ + printf("Closing %s\n",mQaTreeFilename); mTree->Write(); - mQaFile->Close(); + mQaTreeFile->Close(); } + if(mQaHistFile){ + printf("Closing %s\n",mQaHistFilename); + mTrgRate->Write(); + mQaHistFile->Close(); + } + + int tot = NTRG[mNTRG]; + LOG_INFO << "Triggers counts/"<end_event(); + u_int dsm_out = mTrgSim->end_event(); //QA Tree mFlt=0; @@ -332,16 +319,62 @@ int StFcsTriggerSimMaker::Make(){ mFlt=ge->GetFilterResult(); } } - mTrg=dsm_out; - if(mQaFile) mTree->Fill(); + mTcu=dsm_out; + if(mQaTreeFile) mTree->Fill(); //Results - LOG_INFO << Form("Output to DSM = 0x%03x Filter=0x%03x\n",mTrg,mFlt)<> 6) & 0x1) {trg[ 0]=1; mTrg+=1<<0;} //JP2 + if((dsm_out >> 7) & 0x1) {trg[ 1]=1; mTrg+=1<<1;} //JPA1 + if((dsm_out >>10) & 0x1) {trg[ 2]=1; mTrg+=1<<2;} //JPA0 + if((dsm_out >> 8) & 0x1) {trg[ 3]=1; mTrg+=1<<3;} //JPBC1 + if((dsm_out >>11) & 0x1) {trg[ 4]=1; mTrg+=1<<4;} //JPBC0 + if((dsm_out >> 9) & 0x1) {trg[ 5]=1; mTrg+=1<<5;} //JPDE1 + if((dsm_out >>12) & 0x1) {trg[ 6]=1; mTrg+=1<<6;} //JPDE0 + if((dsm_out >>13) & 0x1) {trg[ 7]=1; mTrg+=1<<7;} //DiJP + if((dsm_out >>14) & 0x1) {trg[ 8]=1; mTrg+=1<<8;} //DiJpAsy + if( ((dsm_out >>18) & 0x1) && + ((dsm_out >>26) & 0x1) ) {trg[ 9]=1; mTrg+=1<<9;} //DY + if( ((dsm_out >>17) & 0x1) && + ((dsm_out >>25) & 0x1) ) {trg[10]=1; mTrg+=1<<10;} //Jpsi + if( ((dsm_out >>19) & 0x1) && + ((dsm_out >>27) & 0x1) ) {trg[11]=1; mTrg+=1<<11;} //DYNoEpd + if((dsm_out >>15) & 0x1) {trg[12]=1; mTrg+=1<<12;} //DYAsy + if((dsm_out >> 2) & 0x1) {trg[13]=1; mTrg+=1<<13;} //Had2 + if((dsm_out >> 1) & 0x1) {trg[14]=1; mTrg+=1<<14;} //Had1 + if((dsm_out >> 0) & 0x1) {trg[15]=1; mTrg+=1<<15;} //Had0 + if((dsm_out >> 5) & 0x1) {trg[16]=1; mTrg+=1<<16;} //EM2 + if((dsm_out >> 4) & 0x1) {trg[17]=1; mTrg+=1<<17;} //EM1 + if((dsm_out >> 3) & 0x1) {trg[18]=1; mTrg+=1<<18;} //EM0 + if( ((dsm_out >>18) & 0x1) || + ((dsm_out >>26) & 0x1) ) {trg[19]=1; mTrg+=1<<19;} //ELE2 + if( ((dsm_out >>19) & 0x1) || + ((dsm_out >>27) & 0x1) ) {trg[20]=1; mTrg+=1<<20;} //EM3 + + if(mTrgRate) mTrgRate->Fill(mNTRG); + NTRG[mNTRG]++; + for(int i=0; iFill(i); + NTRG[i]++; + } + } + + LOG_INFO << "Triggers = "; + for(int i=0; istage_2(ecal,hcal,pres,geo,output); + u_short s2_to_dsm; + mTrgSim->stage_2(ecal,hcal,pres,geo,output,&s2_to_dsm); } void StFcsTriggerSimMaker::print4B4(){ @@ -566,3 +599,54 @@ void StFcsTriggerSimMaker::printJP(){ return; } +void StFcsTriggerSimMaker::readThresholdFile(){ + LOG_INFO << Form("Reading Thresholds from %s",mThresholdFile)<PHTTHR=v; + else if(trg=="FCS_EM-HERATIO-THR") mTrgSim->EM_HERATIO_THR=v; + else if(trg=="FCS_HAD-HERATIO-THR") mTrgSim->HAD_HERATIO_THR=v; + else if(trg=="FCS_EMTHR2") mTrgSim->EMTHR2=v; + else if(trg=="FCS_EMTHR1") mTrgSim->EMTHR1=v; + else if(trg=="FCS_EMTHR0") mTrgSim->EMTHR0=v; + else if(trg=="FCS_ELETHR2") mTrgSim->ELETHR2=v; + else if(trg=="FCS_ELETHR1") mTrgSim->ELETHR1=v; + else if(trg=="FCS_ELETHR0") mTrgSim->ELETHR0=v; + else if(trg=="FCS_HADTHR2") mTrgSim->HADTHR2=v; + else if(trg=="FCS_HADTHR1") mTrgSim->HADTHR1=v; + else if(trg=="FCS_HADTHR0") mTrgSim->HADTHR0=v; + else if(trg=="FCS_JPATHR2") mTrgSim->JPATHR2=v; + else if(trg=="FCS_JPATHR1") mTrgSim->JPATHR2=v; + else if(trg=="FCS_JPATHR0") mTrgSim->JPATHR0=v; + else if(trg=="FCS_JPBCTHR2") mTrgSim->JPBCTHR2=v; + else if(trg=="FCS_JPBCTHR1") mTrgSim->JPBCTHR1=v; + else if(trg=="FCS_JPBCTHR0") mTrgSim->JPBCTHR0=v; + else if(trg=="FCS_JPBCTHRD") mTrgSim->JPBCTHRD=v; + else if(trg=="FCS_JPDETHR2") mTrgSim->JPDETHR2=v; + else if(trg=="FCS_JPDETHR1") mTrgSim->JPDETHR1=v; + else if(trg=="FCS_JPDETHR0") mTrgSim->JPDETHR0=v; + else if(trg=="FCS_JPDETHRD") mTrgSim->JPDETHRD=v; + else if(trg=="FCS_EHTTHR") mTrgSim->EHTTHR=v; + else if(trg=="FCS_HHTTHR") mTrgSim->HHTTHR=v; + else if(trg=="FCS_ETOTTHR") mTrgSim->ETOTTHR=v; + else if(trg=="FCS_HTOTTHR") mTrgSim->HTOTTHR=v; + else{ + printf("No Threshold called %s %d\n",trg.Data(),v); + } + } + fclose(F); +} + +//read from offline copy of online runlog DB +void StFcsTriggerSimMaker::readThresholdDb(){ + //to be implemented before run22 online DB moves to offline +} diff --git a/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.h b/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.h index 3878243240a..306e759a37a 100644 --- a/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.h +++ b/StRoot/StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.h @@ -15,6 +15,8 @@ class TFile; class fcs_trg_base; class link_t; class geom_t; +class TTree; +class TH1F; class StFcsTriggerSimMaker : public StMaker{ public: @@ -28,13 +30,21 @@ class StFcsTriggerSimMaker : public StMaker{ void setTrigger(int v) {mTrgSelect=v;}; void setDebug(int v) {mDebug=v;}; void setWriteEventText(char* filename) {mFilename=filename;}; - void setWriteQaFile(char* filename) {mQaFilename=filename;}; + void setWriteQaTree(char* filename) {mQaTreeFilename=filename;}; + void setWriteQaHist(char* filename) {mQaHistFilename=filename;}; void setReadPresMask(char* filename) {mPresMask=filename;}; void setSimMode(int v, int tb=52) {mSimMode=v; mTrgTimebin=tb;} void setTrgTimeBin(int v) {mTrgTimebin=v;} //8 timebin = v-3 to v+4. v=52 for 49~56 + void setThresholdFile(char* file) {mThresholdFile=file;} + void setThresholdDb(int run) {mThresholdDb=run;} + + //factor= 1(ET Match), 0(E Match), 0.5(halfway) + void setEtGain(float v) {mEtFactor=v;} fcs_trg_base* getTriggerEmu() {return mTrgSim;} - void runStage2(link_t ecal[], link_t hcal[], link_t pres[], geom_t& geo, link_t output[]); + + //this is for just running stage2 from macro + void runStage2(link_t ecal[], link_t hcal[], link_t pres[], geom_t &geo, link_t output[]); private: StFcsDb* mFcsDb=0; @@ -50,14 +60,23 @@ class StFcsTriggerSimMaker : public StMaker{ fcs_trg_base* mTrgSim; char* mPresMask=0; - char* mQaFilename=0; - TFile* mQaFile=0; + char* mQaTreeFilename=0; + char* mQaHistFilename=0; + TFile* mQaTreeFile=0; + TFile* mQaHistFile=0; TTree* mTree=0; + TH1F* mTrgRate=0; int mFlt=0; + int mTcu=0; int mTrg=0; + float mEtFactor=1.0; + char* mThresholdFile=0; + int mThresholdDb=0; void print4B4(); void printJP(); + void readThresholdFile(); + void readThresholdDb(); virtual const char *GetCVS() const {static const char cvs[]="Tag $Name: $ $Id: StFcsTriggerSimMaker.h,v 1.2 2021/05/30 21:40:56 akio Exp $ built " __DATE__ " " __TIME__ ; return cvs;}