68 gPARMS->SetDefaultParameter(
"CDC:RUN_CONFIG",
RUN_CONFIG,
"Run to be used as source of configuration files");
71 gPARMS->SetDefaultParameter(
"CDC:DIFFS_ONLY",
DIFFS_ONLY,
"Record (0) all event or (1) only those events where difference are found");
163 Int_t runfile = runnumber;
179 for (
int iroc=1; iroc<5; iroc++) {
182 sprintf(filename,
"/raid12/gluex/rawdata2/Run%06i/RunLog%06i/CDC/COM/roccdc%i_fadc125_fall2018.cnf",runfile,runfile,iroc);
192 printf(
"Looking for config parameter file %s\n",filename);
194 FILE *config = fopen(filename,
"r");
196 if (!config)
printf(
"Could not open config file for cdcroc%i\n",iroc);
201 if (iroc==1) harray = &
roc25h[0][0];
202 if (iroc==2) harray = &
roc26h[0][0];
203 if (iroc==3) harray = &
roc27h[0][0];
204 if (iroc==4) harray = &
roc28h[0][0];
209 fscanf(config,
"################\n");
210 fscanf(config,
"CRATE %s\n",line);
212 fscanf(config,
"################\n");
214 fscanf(config,
"\n\n");
216 while (!feof(config)) {
218 fscanf(config,
"%s\n",line);
219 if (!strcmp(line,
"################\n"))
break;
222 fscanf(config,
"%s %i\n",line,&slotnum);
223 fscanf(config,
"################\n");
227 fscanf(config,
"\n\n");
231 fscanf(config,
"%s ",line);
233 if (!strcmp(line,
"FADC125_DAC_CH_00_17 "))
printf(
"mismatch\n");
234 if (!strcmp(line,
"FADC125_DAC_CH_00_17 "))
break;
236 for (i=0; i<18; i++) fscanf(config,
" %i",&junk);
239 fscanf(config,
"FADC125_DAC_CH_18_35 ");
240 for (i=0; i<18; i++) fscanf(config,
" %i",&junk);
243 fscanf(config,
"FADC125_DAC_CH_36_53 ");
244 for (i=0; i<18; i++) fscanf(config,
" %i",&junk);
247 fscanf(config,
"FADC125_DAC_CH_54_71 ");
248 for (i=0; i<18; i++) fscanf(config,
" %i",&junk);
251 fscanf(config,
"\n\n");
255 fscanf(config,
"%s ",line);
257 if (!strcmp(line,
"FADC125_THR_CH_00_17 "))
printf(
"THR mismatch\n");
260 for (i=0; i<18; i++) fscanf(config,
" %i",harray+72*slotnum+i);
265 fscanf(config,
"FADC125_THR_CH_18_35 ");
266 for (i=18; i<36; i++) fscanf(config,
" %i",harray+72*slotnum+i);
270 fscanf(config,
"FADC125_THR_CH_36_53 ");
271 for (i=36; i<54; i++) fscanf(config,
" %i",harray+72*slotnum+i);
275 fscanf(config,
"FADC125_THR_CH_54_71 ");
276 for (i=54; i<72; i++) fscanf(config,
" %i",harray+72*slotnum+i);
281 fscanf(config,
"\n\n");
285 fscanf(config,
"%s ",line);
287 if (!strcmp(line,
"FADC125_BL_CH_00_17 "))
printf(
"BL mismatch\n");
288 if (!strcmp(line,
"FADC125_BL_CH_00_17 "))
break;
292 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
295 fscanf(config,
"FADC125_BL_CH_18_35 ");
296 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
299 fscanf(config,
"FADC125_BL_CH_36_53 ");
300 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
303 fscanf(config,
"FADC125_BL_CH_54_71 ");
304 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
307 fscanf(config,
"\n\n");
311 fscanf(config,
"%s ",line);
313 if (!strcmp(line,
"FADC125_SIG_CH_00_17 "))
printf(
"SIG mismatch\n");
314 if (!strcmp(line,
"FADC125_SIG_CH_00_17 "))
break;
317 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
320 fscanf(config,
"FADC125_SIG_CH_18_35 ");
321 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
324 fscanf(config,
"FADC125_SIG_CH_36_53 ");
325 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
328 fscanf(config,
"FADC125_SIG_CH_54_71 ");
329 for (i=0; i<18; i++) fscanf(config,
" %f",&fjunk);
336 fscanf(config,
"%s %*s %*s %*s\n",line);
340 fscanf(config,
"%s %*s %*s %*s\n",line);
344 fscanf(config,
"FADC125_TH %i\n",&junk);
346 fscanf(config,
"FADC125_TL %i\n",&junk);
370 for (slotnum=3; slotnum<18; slotnum++) {
372 if (slotnum==11 || slotnum==12)
continue;
373 if (iroc==2 && slotnum==17)
continue;
374 if (iroc==3 && slotnum==17)
continue;
376 for (i=0; i<72; i++) {
377 if (*(harray+72*slotnum+i)==0)
printf(
"hit thres not set for roccdc %i (rocid %i) slot %i ch %i\n",iroc,iroc+24,slotnum,i);
429 vector<const DCDCDigiHit*> digihits;
431 uint32_t nd = (uint32_t)digihits.size();
433 vector<const Df125WindowRawData*> wrdvector;
434 loop->Get(wrdvector);
435 uint32_t nw = (uint32_t)wrdvector.size();
438 if (nw>nd) nhits = nw;
446 const Int_t NSAMPLES = 200;
449 const int straw_offset[29] = {0,0,42,84,138,192,258,324,404,484,577,670,776,882,1005,1128,1263,1398,1544,1690,1848,2006,2176,2346,2528,2710,2907,3104,3313};
455 uint32_t nsamples_pedestal;
456 uint32_t nsamples_integral;
470 uint32_t m_hitsample;
476 uint32_t m_overflows;
479 uint32_t m_net_integral;
503 Int_t tmp_time,tmp_q,tmp_overflows,tmp_pedestal,tmp_amp;
510 const Int_t HIGH_THRESHOLD = 60;
511 const Int_t LOW_THRESHOLD = 10;
516 const Int_t XTHR_SAMPLE = PED + PG;
518 const Int_t NPED = 16;
519 const Int_t NPED2 = 16;
521 const Int_t IBIT = 4;
522 const Int_t ABIT = 3;
523 const Int_t PBIT = 0;
525 const Int_t WINDOW_START = NPED;
526 const Int_t WINDOW_END = 179;
527 const Int_t INT_END = 300;
529 const uint32_t OMAX = 7;
530 const uint32_t
PMAX = 255;
531 const uint32_t AMAX = 511;
532 const uint32_t IMAX = 16383;
535 Int_t adc_subset[NU];
543 eventnum = (ULong64_t)eventnumber;
547 uint32_t w_rocid, w_slot, w_channel;
557 for (
id=0;
id<nd;
id++) {
559 digihit = digihits[id];
561 digihit->GetSingle(cp);
563 digihit->GetSingle(hit);
565 if (!cp)
printf(
"\nno cp - event %lu digihit %i\n\n",(
long unsigned int)eventnum,(
int)
id);
579 if (!wrd)
printf(
"\nno wrd - event %lu roc %i slot %i chan %i \n\n",(
long unsigned int)eventnum,cp->
rocid,cp->
slot,cp->
channel);
587 w_rocid = wrd->
rocid;
595 if (rocid != w_rocid) paired = 0;
596 if (slot != w_slot) paired = 0;
597 if (channel != w_channel) paired = 0;
603 cout <<
"Event " << eventnum << endl;
604 cout <<
"cdcpulse roc " << rocid <<
" slot " << slot <<
" chan " << channel << endl;
605 cout <<
"wrd roc " << w_rocid <<
" slot " << w_slot <<
" chan " << w_channel << endl;
613 ring = digihit->
ring;
614 straw = digihit->
straw;
616 n = straw_offset[ring] + straw;
632 cout <<
"hit found " << endl;
634 printf(
"roc %i slot %i chan %i time %i ped %i integral %i q %f \n",rocid,slot,channel,time,pedestal,integral,hit->
q);
646 for (j=0; j<(Int_t)wrd->
samples.size(); j++) {
647 adc[j] = (Int_t)wrd->
samples[j];
648 if (adc[j] > 4095) adc[j] = 4095;
651 for (j=(Int_t)wrd->
samples.size(); j<NSAMPLES; j++) {
692 for (j=0; j<NU; j++) {
698 HIT_THRES =
roc25h[slot][channel];
699 }
else if (rocid==26) {
700 HIT_THRES =
roc26h[slot][channel];
701 }
else if (rocid==27) {
702 HIT_THRES =
roc27h[slot][channel];
703 }
else if (rocid==28) {
704 HIT_THRES =
roc28h[slot][channel];
708 m_TH = HIGH_THRESHOLD;
709 m_TL = LOW_THRESHOLD;
715 for (j=WINDOW_START-NPED; j<WINDOW_START; j++) {
716 m_initped += (uint32_t)adc[j];
719 m_initped = (uint32_t)(m_initped/(uint32_t)NPED);
739 for (i=0; i<NPED; i++) {
740 tmp_pedestal += adc[WINDOW_START-NPED+i];
743 tmp_pedestal = ( NPED==0 ? 0:(tmp_pedestal/NPED) );
745 threshold = tmp_pedestal + HIT_THRES;
748 i = WINDOW_START - 1 + PG;
754 while ((hitfound==0) && (i<WINDOW_END-1)) {
758 if (adc[i] >= threshold) {
759 if (adc[i+1] >= threshold) {
772 for (i=0; i<NPED2; i++) {
773 tmp_pedestal += adc[hitsample-PG-i];
776 tmp_pedestal = ( NPED2==0 ? 0:(tmp_pedestal/NPED2) );
781 m_pedestal = (uint32_t)tmp_pedestal;
786 m_hitsample = (uint32_t)hitsample;
788 for (j=0; j<NU; j++) {
789 adc_subset[j] = adc[hitsample+j-XTHR_SAMPLE];
798 cdc_time(tmp_time, tmp_q, adc_subset, NU, PG, HIGH_THRESHOLD, LOW_THRESHOLD);
800 timesample = hitsample-XTHR_SAMPLE + (Int_t)(0.1*tmp_time);
802 cdc_integral(tmp_integral, tmp_overflows, timesample, adc, WINDOW_END, INT_END);
803 tmp_amp = (Int_t)adc[timesample];
805 cdc_max(tmp_amp, pktime, timesample, adc, WINDOW_END);
808 m_time = (uint32_t)10*(uint32_t)(hitsample-XTHR_SAMPLE) + (uint32_t)tmp_time;
814 m_q = (uint32_t)tmp_q;
815 m_integral = (uint32_t)tmp_integral;
816 m_overflows = (uint32_t)tmp_overflows;
817 m_amp = (uint32_t)tmp_amp;
819 if (m_integral > m_pedestal*(WINDOW_END-timesample) ) m_net_integral = m_integral - m_pedestal*(WINDOW_END-timesample);
822 s_pedestal = m_pedestal>>PBIT;
823 if (s_pedestal > PMAX) s_pedestal =
PMAX;
826 if (s_amp > AMAX) s_amp = AMAX;
828 s_integral = m_integral>>IBIT;
829 if (s_integral > IMAX) s_integral = IMAX;
831 d_time = (Int_t)m_time - (Int_t)time;
833 if ((m_q > 0) && (q == 0) ) d_q = 1;
834 if ((m_q == 0) && (q > 0) ) d_q = 1;
836 d_overflows = (Int_t)m_overflows - (Int_t)overflows;
837 if ((overflows==OMAX) && (m_overflows > overflows)) d_overflows = 0;
839 d_pedestal = (Int_t)s_pedestal - (Int_t)
pedestal;
841 d_amp = (Int_t)s_amp - (Int_t)amp;
843 d_integral = (Int_t)s_integral - (Int_t)integral;
846 if (d_time || d_q || d_overflows || d_pedestal || d_amp || d_integral) diffs = 1;
904 for (j=0; j<NSAMPLES; j++) {
uint32_t first_max_amp
from second word
void cdc_max(Int_t &, Int_t &, Int_t, Int_t[], Int_t)
if(locHist_BCALShowerPhiVsZ!=NULL)
void cdc_time(Int_t &, Int_t &, Int_t[], Int_t, Int_t, Int_t, Int_t)
sprintf(text,"Post KinFit Cut")
void Register_Single(string locBranchName)
jerror_t init(void)
Called once at program start.
void Fill_Array(string locBranchName, const DType &locData, size_t locArrayIndex)
bool Create_Branches(const DTreeBranchRegister &locTreeBranchRegister)
uint32_t overflow_count
from first word
static char index(char c)
static Int_t roc26h[19][72]
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
uint32_t nsamples_pedestal
number of samples used in integral
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
JEventProcessor_cdc_emu()
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
~JEventProcessor_cdc_emu()
void Fill(DTreeFillData &locTreeFillData)
static DTreeInterface * Create_DTreeInterface(string locTreeName, string locFileName)
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
vector< uint16_t > samples
jerror_t fini(void)
Called after last event of last event source has been processed.
DTreeInterface * dTreeInterface
void Register_FundamentalArray(string locBranchName, string locArraySizeName, size_t locInitialArraySize=10)
uint32_t time_quality_bit
from first word
static Int_t roc27h[19][72]
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static Int_t roc25h[19][72]
uint32_t nsamples_integral
number of samples used in pedestal
static TH1I * pedestal[nChan]
static Int_t roc28h[19][72]
bool emulated
true if emulated values are copied to the main input
printf("string=%s", string)
uint32_t pedestal
pedestal info used by FPGA (if any)
static thread_local DTreeFillData dTreeFillData
void cdc_integral(Long_t &, Int_t &, Int_t, Int_t[], Int_t, Int_t)
void Fill_Single(string locBranchName, const DType &locData)