//--------------------------------------------- // Go4 Tasca analysis // Author: Hans G. Essel // H.Essel@gsi.de // GSI, Experiment Electronics, Data Processing // July 2021 - cleanup by JAM (j.adamczewski@gsi.de) //--------------------------------------------- #include "TascaUnpackProc.h" #include "TGo4EventEndException.h" #include "Riostream.h" #include #include #include "TRandom.h" #include #include "TObjArray.h" #include "TObjString.h" #include "TH1.h" #include "TH2.h" #include "TCutG.h" #include "snprintf.h" #include "TPaveStats.h" #include "s_filhe_swap.h" #include "s_bufhe_swap.h" #include "TROOT.h" #include "TSystem.h" #include "TGo4MbsEvent.h" #include "TGo4FitDataHistogram.h" #include "TGo4FitPeakFinder.h" #include "TGo4FitModelGauss1.h" #include "TGo4FitParameter.h" #include "TGo4MbsEvent.h" #include "TGo4WinCond.h" #include "TGo4PolyCond.h" #include "TGo4CondArray.h" #include "TGo4Picture.h" #include "TGo4UserException.h" #include "TascaUnpackEvent.h" #include "TascaAnalysis.h" #define MWD 1 #ifdef MWD #define POLARITY 0 // 0: positive signals, 1 negative signals #define l_gap 100 // MWF gap size #define l_win 200 // MWF window size #define pre_tr 500 // pre-trigger trace length Int_t l_A1; Int_t l_A2; Real_t d_n_l; Real_t p_n; Real_t r_n; Real_t ss_n; Real_t baseline; Real_t ampl; #endif // MWD #define RON "\x1B[7m" #define RES "\x1B[0m" // if Histo_On is defined than comment Histo_Off #define Histo_On //#define Histo_Off #define Trace_On //#define Trace_Off #ifdef USE_MBS_PARAM static UInt_t l_tr[MAX_TRACE_SIZE]; static UInt_t pro_tr[1300]; static Double_t f_tr_blr[MAX_TRACE_SIZE]; static UInt_t l_sfp_slaves[MAX_SFP] = { MAX_SLAVE, MAX_SLAVE, MAX_SLAVE, MAX_SLAVE }; static UInt_t l_slaves = 0; static UInt_t l_trace = 0; static UInt_t l_e_filt = 0; #else static UInt_t l_tr [TRACE_SIZE]; static Double_t f_tr_blr[TRACE_SIZE]; static UInt_t l_sfp_slaves [MAX_SFP] = NR_SLAVES; static UInt_t l_sfp_adc_type[MAX_SFP] = ADC_TYPE; #endif // UInt_t max_over, over_flow_act, lenght_over_flow; static UInt_t l_adc_type; //*********************************************************** TascaUnpackProc::TascaUnpackProc() : TGo4EventProcessor() { } //*********************************************************** // this one is used TascaUnpackProc::TascaUnpackProc(const char* name) : TGo4EventProcessor(name) { cout << "Tasca> TascaUnpackProc: Create" << endl; ER_out = fopen("ERnum.txt", "w+"); // OverFlow = fopen("Overflow_FF.dat","w+"); //ADN spillTime0 = 0; spillIndex = 0; spillOn = kFALSE; spillTest = kFALSE; memset((void*) spillBins, 0, sizeof(spillBins)); evcount = 0; gammaTimeLast = 0; secTimeLast = 0; mysecTimeLast = 0; adcTimeLast = 0; beam_pro_sec = 0; beam_pro_min = 0; ruth_pro_sec = 0; ruth_pro_min = 0; start = 0; start_sec = 0; last_time = 0; reload_time = 0; time = 0; } //*********************************************************** TascaUnpackProc::~TascaUnpackProc() { fprintf(ER_out, "9999999 \n"); fclose(ER_out); // fclose(OverFlow); cout << "Tasca> TascaUnpackProc: Delete" << endl; } //*********************************************************** //*********************************************************** //----------------------------------------------------------- void TascaUnpackProc::TascaUnpack(TascaUnpackEvent* pUP) { TGo4MbsSubEvent* psubevt; // UInt_t timestamp,lat0,lat1,lat2,lat3; // UInt_t timediff; // Bool_t takeEvent=kFALSE; // taken from febex: UInt_t l_i, l_j, l_k, l_l; uint32_t *pl_se_dat; uint32_t *pl_tmp; UInt_t l_dat_len; UInt_t l_dat_len_byte; UInt_t l_dat; UInt_t l_trig_type; UInt_t l_trig_type_triva; UInt_t l_sfp_id; UInt_t l_feb_id; UInt_t l_cha_id; UInt_t l_n_hit; // UInt_t l_hit_id; UInt_t l_hit_cha_id; ULong64_t ll_time; ULong64_t ll_trg_time; // Long64_t ll_hit_time; UInt_t l_ch_hitpat[MAX_SFP][MAX_SLAVE][N_CHA]; UInt_t l_ch_hitpat_tr[MAX_SFP][MAX_SLAVE][N_CHA]; UInt_t l_first_trace[MAX_SFP][MAX_SLAVE]; UInt_t l_cha_head; UInt_t l_cha_size; UInt_t l_trace_head; UInt_t l_trace_size; UInt_t l_trace_trail; UInt_t l_spec_head; UInt_t l_spec_trail; UInt_t l_n_hit_in_cha; UInt_t l_only_one_hit_in_cha; UInt_t l_more_than_1_hit_in_cha; UInt_t l_hit_time_sign; Int_t l_hit_time = 0; UInt_t l_hit_cha_id2; UInt_t l_fpga_energy_sign; Int_t l_fpga_energy; // UInt_t l_trapez_e_found [MAX_SFP][MAX_SLAVE][N_CHA]; UInt_t l_fpga_e_found[MAX_SFP][MAX_SLAVE][N_CHA]; //UInt_t l_trapez_e [MAX_SFP][MAX_SLAVE][N_CHA]; UInt_t l_fpga_e[MAX_SFP][MAX_SLAVE][N_CHA]; UInt_t l_dat_fir; UInt_t l_dat_sec; // static UInt_t l_evt_ct=0; static UInt_t l_evt_ct_phys = 0; UInt_t l_bls_start = BASE_LINE_SUBT_START; UInt_t l_bls_stop = BASE_LINE_SUBT_START + BASE_LINE_SUBT_SIZE; // Double_t f_bls_val = 0.; Int_t l_fpga_filt_on_off; Int_t l_fpga_filt_mode; Int_t l_dat_trace; Int_t l_dat_filt; Int_t l_filt_sign; static UInt_t l_more_1_hit_ct = 0; static UInt_t l_first = 0; pUnpackEvent = pUP; fInput = (TGo4MbsEvent*) GetInputEvent(); // from this if ((fInput != 0) & (fInput->GetTrigger() != 14) & (fInput->GetTrigger() != 15) & (fInput->GetDlen() != 36)) { // cout << "Event=" << fInput->GetCount() << endl; pUnpackEvent->fievent_number = fInput->GetCount(); fInput->ResetIterator(); //++++++++++++++++++++++++++++++++++++++++++ while ((psubevt = fInput->NextSubEvent()) != 0) { //data in subevent UInt_t control = psubevt->GetControl(); UInt_t procid = psubevt->GetProcid(); // cout<< control<<" "<GetTrigger(); if (l_trig_type_triva == 1) { l_evt_ct_phys++; } pl_se_dat = (uint32_t *) psubevt->GetDataField(); l_dat_len = psubevt->GetDlen(); l_dat_len_byte = (l_dat_len - 2) * 2; //printf ("sub-event data size: 0x%x, %d \n", l_dat_len, l_dat_len); //printf ("sub-event data size (bytes): 0x%x, %d \n", l_dat_len_byte, l_dat_len_byte); //fflush (stdout); pl_tmp = pl_se_dat; if (pl_se_dat == (UInt_t*) 0) { printf("ERROR>> "); printf("pl_se_dat: %p, ", pl_se_dat); printf("l_dat_len: 0x%x, ", (UInt_t) l_dat_len); printf("l_trig_type_triva: 0x%x \n", (UInt_t) l_trig_type_triva); fflush(stdout); goto bad_event; } if ((*pl_tmp) == 0xbad00bad) { printf("ERROR>> found bad event (0xbad00bad) \n"); goto bad_event; } #ifdef WR_TIME_STAMP // 4 first 32 bits must be TITRIS time stamp l_dat = *pl_tmp++; if (l_dat != SUB_SYSTEM_ID) { printf ("ERROR>> 1. data word is not sub-system id: %d \n"); printf ("should be: 0x%x, but is: 0x%x\n", SUB_SYSTEM_ID, l_dat); } if (l_dat != 0x100) { goto bad_event; } l_dat = (*pl_tmp++) >> 16; if (l_dat != TS__ID_L16) { printf ("ERROR>> 2. data word does not contain low 16bit identifier: %d \n"); printf ("should be: 0x%x, but is: 0x%x\n", TS__ID_L16, l_dat); } l_dat = (*pl_tmp++) >> 16; if (l_dat != TS__ID_M16) { printf ("ERROR>> 3. data word does not contain low 16bit identifier: %d \n"); printf ("should be: 0x%x, but is: 0x%x\n", TS__ID_M16, l_dat); } l_dat = (*pl_tmp++) >> 16; if (l_dat != TS__ID_H16) { printf ("ERROR>> 4. data word does not contain low 16bit identifier: %d \n"); printf ("should be: 0x%x, but is: 0x%x\n", TS__ID_H16, l_dat); } #endif // WR_TIME_STAMP // extract analysis parameters from MBS data // ATTENTION: these data is only present if WRITE_ANALYSIS_PARAM // is enabled in corresponding f_user.c // WRITE_ANALYSIS_PARAM (in mbs) and USE_MBS_PARAM (in go4) must be used always together #ifdef USE_MBS_PARAM l_slaves = *pl_tmp++; l_trace = *pl_tmp++; l_e_filt = *pl_tmp++; pl_tmp += 4; #endif // USE_MBS_PARAM if (l_first == 0) { l_first = 1; #ifdef USE_MBS_PARAM printf("debug: 0x%x, 0x%x, 0x%x \n", l_slaves, l_trace, l_e_filt); fflush(stdout); #endif// USE_MBS_PARAM f_make_histo(0); } #ifdef Histo_On // printf(" TEST 2 \n"); for (l_i = 0; l_i < MAX_SFP; l_i++) { if (l_sfp_slaves[l_i] != 0) { for (l_j = 0; l_j < l_sfp_slaves[l_i]; l_j++) { for (l_k = 0; l_k < N_CHA; l_k++) { // h_trace [l_i][l_j][l_k]->Reset (""); // h_trace_blr [l_i][l_j][l_k]->Reset (""); h_trapez_fpga[l_i][l_j][l_k]->Reset(""); h_mwd_f[l_i][l_j][l_k]->Reset(""); l_ch_hitpat[l_i][l_j][l_k] = 0; l_ch_hitpat_tr[l_i][l_j][l_k] = 0; //l_fpga_e_found[l_i][l_j][l_k] = 0; // l_trapez_e [l_i][l_j][l_k] = 0; // l_fpga_e [l_i][l_j][l_k] = 0; } h_hitpat[l_i][l_j]->Fill(-2, 1); h_hitpat_tr[l_i][l_j]->Fill(-2, 1); l_first_trace[l_i][l_j] = 0; } } } #endif// Histo_On while ((pl_tmp - pl_se_dat) < (l_dat_len_byte / 4)) { //sleep (1); //printf (" begin while loop \n"); fflush (stdout); l_dat = *pl_tmp++; // must be padding word or channel header //printf ("l_dat 0x%x \n", l_dat); if ((l_dat & 0xfff00000) == 0xadd00000) // begin of padding 4 byte words { //printf ("padding found \n"); l_dat = (l_dat & 0xff00) >> 8; pl_tmp += l_dat - 1; // increment by pointer by nr. of padding 4byte words } else if ((l_dat & 0xff) == 0x34) //channel header { l_cha_head = l_dat; //printf ("l_cha_head: 0x%x \n", l_cha_head); l_trig_type = (l_cha_head & 0xf00) >> 8; l_sfp_id = (l_cha_head & 0xf000) >> 12; l_feb_id = (l_cha_head & 0xff0000) >> 16; l_cha_id = (l_cha_head & 0xff000000) >> 24; if ((l_sfp_id > (MAX_SFP - 1)) || (l_sfp_id < 0)) { printf("ERROR>> l_spf_id: %d \n", l_sfp_id); fflush(stdout); goto bad_event; } if ((l_feb_id > (MAX_SLAVE - 1)) || (l_feb_id < 0)) { printf("ERROR>> l_feb_id: %d \n", l_feb_id); fflush(stdout); goto bad_event; } if ((l_cha_id > (N_CHA - 1)) || (l_cha_id < 0)) { if (l_cha_id != 0xff) { printf("ERROR>> l_cha_id: %d \n", l_cha_id); fflush(stdout); goto bad_event; } } if (((l_cha_head & 0xff) >> 0) != 0x34) { printf("ERROR>> channel header type is not 0x34 \n"); goto bad_event; } if ((l_cha_head & 0xff000000) == 0xff000000) // special channel 0xff for E,t from fpga { //printf ("special channel \n"); // special channel data size l_cha_size = *pl_tmp++; //printf ("l_cha_head: 0x%x \n", l_cha_head); sleep (1); //printf ("l_cha_size: 0x%x \n", l_cha_size); l_spec_head = *pl_tmp++; if ((l_spec_head & 0xff000000) != 0xaf000000) { printf("ERROR>> E,t summary: wrong header is 0x%x, must be: 0x%x\n", (l_spec_head & 0xff000000) >> 24, 0xaf); goto bad_event; //sleep (1); } // ll_trg_time = (Long64_t)*pl_tmp++; // printf ("ll_trg_time: %x \n", ll_trg_time); //printf ("l_cha_size: 0x%x \n", l_cha_size); // printf ("ll_trg_time_1: %x \n", *pl_tmp); // ll_time = (Long64_t)*pl_tmp++; // printf ("ll_time: %x \n", ll_time); // printf ("ll_time_1: %x \n", *pl_tmp); // ll_trg_time += ((ll_time & 0xffffff) << 32); // printf ("ll_trg_time_add: %x \n", ll_trg_time); // printf ("ll_trg_time_add_1: %16d \n", ll_trg_time); ll_trg_time = (Long64_t) *pl_tmp++; ll_time = (Long64_t) *pl_tmp++; ll_time += ((ll_trg_time & 0xffffff) << 32); //printf(" no corr %lld %10.2f\n",ll_time, ll_time*0.00000002); if (last_time > (ll_time + 500)) { reload_time++; time = last_time; //this reset of the time is needed once the bad event occurs in the mbs thus the time is restarted //cout<<" reload_time:"<fiSystemSec = abs_time; //printf(" corr %lld %10.2f\n",abs_time, abs_time*0.00000002); // if(time>ll_time) ll_time=last_time+ll_time; // pUnpackEvent->fiSystemSec=ll_time; // printf ("ll_trg_time_48bit: Hex=%llx Int=%lld \n", ll_time,ll_time ); // ll_time += ((ll_trg_time & 0xffffff) << 32); // printf ("ll_trg_time_48bit: Hex=%llx Int=%lld \n", ll_trg_time,ll_trg_time); l_n_hit = (l_cha_size - 16) >> 3; // printf ("#hits: %d \n", l_n_hit); if (l_trig_type_triva == 1) // physics event { // h_hitpat[l_sfp_id][l_feb_id]->Fill (-1, 1); // printf(" TEST 3 \n"); for (l_i = 0; l_i < l_n_hit; l_i++) { l_dat = *pl_tmp++; // hit time from fpga (+ other info) l_hit_cha_id = (l_dat & 0xf0000000) >> 28; l_n_hit_in_cha = (l_dat & 0xf000000) >> 24; l_more_than_1_hit_in_cha = (l_dat & 0x400000) >> 22; l_only_one_hit_in_cha = (l_dat & 0x100000) >> 20; l_ch_hitpat[l_sfp_id][l_feb_id][l_hit_cha_id] = l_n_hit_in_cha; if (l_more_than_1_hit_in_cha == 1) { // printf(" TEST 4 \n"); l_more_1_hit_ct++; // printf ("%d More than 1 hit found for SFP: %d FEBEX: %d CHA: %d:: %d \n", // l_more_1_hit_ct, l_sfp_id, l_feb_id, l_hit_cha_id, l_n_hit_in_cha); l_hit_time_sign = (l_dat & 0x8000) >> 15; l_hit_time = l_dat & 0x7ff; // positive := AFTER trigger, relative to trigger time if (l_hit_time_sign == 1) // negative sign { l_hit_time = l_hit_time * (-1); // negative := BEFORE trigger, relative to trigger time } // baatar printf ("multi!! feb: %d, cha: %d, hit fpga time: %d \n", l_feb_id, l_hit_cha_id, l_hit_time); if (l_feb_id == 12 && l_hit_cha_id == 6) { pUnpackEvent->ffGammaE_hit[1] = l_n_hit_in_cha; pUnpackEvent->fiGammaT_hit[1] = l_hit_time; } if (l_feb_id == 11 && l_hit_cha_id == 0) { pUnpackEvent->ffGammaE_hit[0] = l_n_hit_in_cha; pUnpackEvent->fiGammaT_hit[0] = l_hit_time; } //end gamma detectors if (l_feb_id < 3) { pUnpackEvent->fiStopXL_hit[l_feb_id * 16 + l_hit_cha_id] = l_n_hit_in_cha; pUnpackEvent->fiStopXL_hit_TAC[l_feb_id * 16 + l_hit_cha_id] = l_hit_time; } if (l_feb_id > 2 && l_feb_id < 9) { pUnpackEvent->fiStopYL_hit[(l_feb_id - 3) * 16 + l_hit_cha_id] = l_n_hit_in_cha; pUnpackEvent->fiStopYL_hit_TAC[(l_feb_id - 3) * 16 + l_hit_cha_id] = l_hit_time; } fflush(stdout); } if ((l_more_than_1_hit_in_cha == 1) && (l_only_one_hit_in_cha == 1)) { printf("ERROR>> haeh? \n"); fflush(stdout); } // printf ("end c1d \n"); if (l_only_one_hit_in_cha == 1) { // printf(" TEST 5 \n"); // printf ("%d Only 1 hit found for SFP: %d FEBEX: %d CHA: %d:: %d \n", // l_only_one_hit_in_cha, l_sfp_id, l_feb_id, l_hit_cha_id, l_n_hit_in_cha); l_hit_time_sign = (l_dat & 0x8000) >> 15; l_hit_time = l_dat & 0x7ff; // positive := AFTER trigger, relative to trigger time if (l_hit_time_sign == 1) // negative sign { l_hit_time = l_hit_time * (-1); // negative := BEFORE trigger, relative to trigger time } // printf ("one!! feb: %d, cha: %d, hit fpga time: %d \n", l_feb_id, l_hit_cha_id, l_hit_time); // printf ("end c1e \n"); // cout<Fill(l_hit_time); h_hitpat[l_sfp_id][l_feb_id]->Fill(l_hit_cha_id, 1); #endif // Histo_On } // printf(" TEST 6 \n"); // printf ("end c1f \n"); // h_hitpat[l_sfp_id][l_feb_id]->Fill (l_hit_cha_id, l_n_hit_in_cha); l_dat = *pl_tmp++; // energy from fpga (+ other info) // printf("l dat for energy \t %x ", l_dat); l_hit_cha_id2 = (l_dat & 0xf0000000) >> 28; if (l_hit_cha_id != l_hit_cha_id2) { printf("ERROR>> hit channel ids differ in energy and time data word\n"); goto bad_event; } if ((l_hit_cha_id > (N_CHA - 1)) || (l_hit_cha_id < 0)) { printf("ERROR>> hit channel id: %d \n", l_hit_cha_id); fflush(stdout); goto bad_event; } l_fpga_energy_sign = (l_dat & 0x800000) >> 23; //l_fpga_energy = l_dat & 0x7ffff; // positiv l_fpga_energy = l_dat & 0x3fffff; // positiv if (l_fpga_energy_sign == 1) // negative sign { l_fpga_energy = l_fpga_energy * (-1); // negative } // printf ("multi: feb %d, cha: %d, hit fpga energy: %d \n", l_feb_id, l_hit_cha_id2, l_fpga_energy); // previous line from Baatar commented ADN 13.05 // printf(" TEST 6 \n"); if (l_fpga_energy > -2000000. && l_fpga_energy < 2000000.) { // start the gamma detectors deconding if (l_feb_id == 12 && l_hit_cha_id == 6) { pUnpackEvent->ffGammaE[1] = l_fpga_energy; pUnpackEvent->fiGammaT[1] = l_hit_time; } if (l_feb_id == 11 && l_hit_cha_id == 0) { pUnpackEvent->ffGammaE[0] = l_fpga_energy; pUnpackEvent->fiGammaT[0] = l_hit_time; } //end gamma detectors if (l_feb_id < 3) { pUnpackEvent->ffStopXL[l_feb_id * 16 + l_hit_cha_id] = l_fpga_energy; pUnpackEvent->fiStopXL_TAC[l_feb_id * 16 + l_hit_cha_id] = l_hit_time; } if (l_feb_id > 2 && l_feb_id < 9) { pUnpackEvent->ffStopYL[(l_feb_id - 3) * 16 + l_hit_cha_id] = l_fpga_energy; pUnpackEvent->fiStopYL_TAC[(l_feb_id - 3) * 16 + l_hit_cha_id] = l_hit_time; } // if(l_feb_id>8 && l_feb_id<11) { // pUnpackEvent->ffStopXL[l_feb_id*16+l_hit_cha_id]=l_fpga_energy; // pUnpackEvent->fiStopXL_TAC[l_feb_id*16+l_hit_cha_id]=l_hit_time; // } // if(l_feb_id==12 && l_hit_cha_id==5) { // pUnpackEvent->ffChopper_Amp=l_fpga_energy; // // pUnpackEvent->fiStopXL_TAC[l_feb_id*16+l_hit_cha_id]=500+l_hit_time; // } } if (l_only_one_hit_in_cha == 1) { // printf ("end c5 \n"); l_fpga_energy_sign = (l_dat & 0x800000) >> 23; //l_fpga_energy = l_dat & 0x7ffff; // positiv l_fpga_energy = l_dat & 0x3fffff; // positiv if (l_fpga_energy_sign == 1) // negative sign { l_fpga_energy = l_fpga_energy * (-1); // negative } // printf ("feb %d, cha: %d, hit fpga energy: %d \n", l_feb_id, l_hit_cha_id2, l_fpga_energy); //printf ("sfp: %d, feb: %d, cha: %d \n", l_sfp_id, l_feb_id, l_hit_cha_id); // printf(" TEST 8 \n"); #ifdef Histo_On h_fpga_e[l_sfp_id][l_feb_id][l_hit_cha_id]->Fill(l_fpga_energy); l_fpga_e_found[l_sfp_id][l_feb_id][l_hit_cha_id] = 1; l_fpga_e[l_sfp_id][l_feb_id][l_hit_cha_id] = l_fpga_energy; // printf(" TEST 9 \n"); #endif } } } l_spec_trail = *pl_tmp++; if ((l_spec_trail & 0xff000000) != 0xbf000000) { printf("ERROR>> E,t summary: wrong header is 0x%x, must be: 0x%x\n", (l_spec_trail & 0xff000000) >> 24, 0xbf); goto bad_event; //sleep (1); } } else // real channel { // printf(" TEST 10 Sampling data \n"); //printf ("real channel \n"); // channel data size l_cha_size = *pl_tmp++; // trace header l_trace_head = *pl_tmp++; //printf ("trace header \n"); if (((l_trace_head & 0xff000000) >> 24) != 0xaa) { printf("ERROR>> trace header id is not 0xaa \n"); goto bad_event; } l_fpga_filt_on_off = (l_trace_head & 0x80000) >> 19; l_fpga_filt_mode = (l_trace_head & 0x40000) >> 18; //printf ("fpga filter on bit: %d, fpga filter mode: %d \n", l_fpga_filt_on_off, l_fpga_filt_mode); //fflush (stdout); //sleep (1); // printf(" TEST n \n"); // getchar(); #ifdef Trace_On if (l_trig_type == 1) // physics event { if (l_first_trace[l_sfp_id][l_feb_id] == 0) { l_first_trace[l_sfp_id][l_feb_id] = 1; // h_hitpat_tr[l_sfp_id][l_feb_id]->Fill (-1, 1); } // h_hitpat_tr[l_sfp_id][l_feb_id]->Fill (l_cha_id, 1); l_ch_hitpat_tr[l_sfp_id][l_feb_id][l_cha_id]++; // now trace l_trace_size = (l_cha_size / 4) - 2; // in longs/32bit if (l_fpga_filt_on_off == 0) // only trace. no fpga filter trace data { over_flow_act = 0; max_over = 0; for (l_l = 0; l_l < l_trace_size; l_l++) // loop over traces { // disentangle data l_dat_fir = *pl_tmp++; l_dat_sec = l_dat_fir; #ifdef USE_MBS_PARAM l_adc_type = (l_trace_head & 0x800000) >> 23; #else l_adc_type = (l_sfp_adc_type[l_sfp_id] >> l_feb_id) & 0x1; #endif if (l_adc_type == 0) // 12 bit { l_dat_fir = l_dat_fir & 0xfff; l_dat_sec = (l_dat_sec >> 16) & 0xfff; } if (l_adc_type == 1) // 14 bit { l_dat_fir = l_dat_fir & 0x3fff; l_dat_sec = (l_dat_sec >> 16) & 0x3fff; } #ifdef Histo_On h_trace[l_sfp_id][l_feb_id][l_cha_id]->SetBinContent(l_l * 2, l_dat_fir); h_trace[l_sfp_id][l_feb_id][l_cha_id]->SetBinContent(l_l * 2 + 1, l_dat_sec); // if((l_feb_id<11)) { // fprintf(ER_out,"%d %d %d\n",l_l*2 , l_dat_fir, pUnpackEvent->fievent_number); // fprintf(ER_out,"%d %d %d\n",l_l*2+1, l_dat_sec, pUnpackEvent->fievent_number); // } #endif l_tr[l_l * 2] = l_dat_fir; l_tr[l_l * 2 + 1] = l_dat_sec; pro_tr[l_l * 2] = l_dat_fir; pro_tr[l_l * 2 + 1] = l_dat_sec; } l_trace_size = l_trace_size * 2; //added by baatar moving window filter l_A1 = 0; l_A2 = 0; d_n_l = 0.; baseline = 0.; ampl = 0.; r_n = 0.; p_n = 0.; ss_n = 0.; //Int_t satur_fr = 0; //Int_t satur_ba = 0; //Int_t sat_feb_id = 0; //Int_t sat_cha_id = 0; /* for (Int_t k=0; k<1300; k++) // loop for amplitude estimation and it is enough to use the channels up 1000 { if(l_feb_id==0 && l_cha_id==0) fprintf(ER_out,"%d %d %d %d %d\n",k, l_tr[k], pro_tr[k], l_cha_id, pUnpackEvent->fievent_number); } */for (Int_t k = 0; k < 1300; k++) // loop for amplitude estimation and it is enough to use the channels up 1000 // for (k=(l_gap+l_win); k<1300; k++) // loop for saturation finding { if (pro_tr[k] > 3000 && (k == (l_gap + l_win) || k == 800) && l_feb_id == 12 && l_cha_id == 2) { pUnpackEvent->fiMicro = 1; //re-identification of the fpga-signal of the micro via the trace entrance!! // printf("micro_from_trace %d %d %d %d %4.7f %d \n",l_cha_id, pUnpackEvent->fiMicro, k, pro_tr[k], pUnpackEvent->fiSystemSec*1e-8, pUnpackEvent->fievent_number); } // if(pro_tr[k]>=9000 && l_feb_id==02 && l_hit_cha_id==0) { // pUnpackEvent->fiMicro=1; //re-identification of the fpga-signal of the micro via the trace entrance!! // printf("micro_from_trace %d %d %4.7f \n",pUnpackEvent->fiMicro, k, pUnpackEvent->fiSystemSec*1e-8); // // } // // if(pro_tr[k]>=5000 && l_feb_id==12 && l_cha_id==1) { // pUnpackEvent->fiMacro=1; //re-identification of the fpga-signal of the prolonged macro via the trace entrance!! printf("\t prolonged micro_from_trace %d\n",pUnpackEvent->fiMacro); // // } // if (k < (l_gap + (l_win))) { // l_A1 = pro_tr[k]; // l_A2 = pro_tr[k-l_win-l_gap]; //printf ("index: %d, A1: %d, A2 %d, A1-A2: %d, norm %d \n", k, l_A1, l_A2, l_A1-l_A2, l_win); //printf ("(A1-A2)/norm: %d, %f \n", (l_A1 - l_A2) / l_win, (Real_t)(l_A1 - l_A2) / (Real_t) l_win); // fprintf(ER_out,"%d %f %d %d %d %d\n",k, 0., pro_tr[k], l_feb_id, l_cha_id, pUnpackEvent->fievent_number); } else { l_A1 = pro_tr[k] - pro_tr[k - l_win]; l_A2 = pro_tr[k - l_gap] - pro_tr[k - l_win - l_gap]; // l_A1 += pro_tr[k] - pro_tr[k-l_win]; // l_A2 += pro_tr[k-l_win-l_gap] - pro_tr[k-(2*l_win)-l_gap]; d_n_l = (Real_t) (l_A1 - l_A2); p_n = p_n + d_n_l; r_n = p_n + (1650.) * d_n_l; ss_n = ss_n + r_n; // d_n_l= (Real_t)(l_A1 - l_A2)+1650.* (Real_t)(l_A1 - l_A2); if (k < (1300)) { //h_mwd_f[l_sfp_id][l_feb_id][l_cha_id]->Fill (k, (Real_t)(l_A1 - l_A2) / (Real_t) l_win); //printf ("index: %d, A1: %d, A2 %d, A1-A2: %d, norm %d \n", k, l_A1, l_A2, l_A1-l_A2, l_win); //printf ("(A1-A2)/norm: %d, %f \n", (l_A1 - l_A2) / l_win, (Real_t)(l_A1 - l_A2) / (Real_t) l_win); if (k >= 400 && k < (450)) { baseline = baseline + ss_n / (Real_t) l_gap / 1650.; } if (k >= 570 && k < 590) { ampl = ampl + ss_n / (Real_t) l_gap / 1650.; } { // fprintf(ER_out,"%d %f %d %d %d %d\n",k, ss_n / (Real_t) l_gap / 1650., pro_tr[k], l_feb_id, l_cha_id, pUnpackEvent->fievent_number); } h_mwd_f[l_sfp_id][l_feb_id][l_cha_id]->Fill(k, ss_n / (Real_t) l_gap / 1650.); //h_mwd_f[l_sfp_id][l_feb_id][l_cha_id]->Fill (k, pro_tr[k]); if (k == (1300 - (l_win) - l_gap) - 10) { // pUnpackEvent->ffStopXL[60]= (float_t) ampl/(Real_t) (l_win- l_gap - 20)- (baseline/((Real_t) (pre_tr-l_win-l_gap) -40)); // printf ("(A1-A2)/norm: %d, %d %f \n", pUnpackEvent->fievent_number, (-1.)*h_mwd_f[l_sfp_id][l_feb_id][l_cha_id]->GetMinimum ()); // cout<fievent_number<<" "<Fill (ampl/(Real_t) (l_win- l_gap - 20)); if (l_feb_id < 3) { pUnpackEvent->ffStopXH[l_feb_id * 16 + l_cha_id] = (-1.) * (ampl / (590. - 570.) - baseline / (450. - 400.)); // pUnpackEvent->fiStopXL_TAC[l_feb_id*16+l_hit_cha_id]=l_hit_time; h_peak[l_sfp_id][l_feb_id][l_cha_id]->Fill( (-1.) * (ampl / (590. - 570.) - baseline / (450. - 400.))); } if (l_feb_id > 2 && l_feb_id < 10) { pUnpackEvent->ffStopYH[l_feb_id * 16 + l_cha_id] = (1.) * (ampl / (590. - 570.) - baseline / (450. - 400.)); h_peak[l_sfp_id][l_feb_id][l_cha_id]->Fill( (1.) * (ampl / (590. - 570.) - baseline / (450. - 400.))); } // if(l_feb_id==12 && l_hit_cha_id==6) // { // pUnpackEvent->ffGammaE[1]=ampl/20.-baseline/20.; // // } // // if(l_feb_id==11 && l_hit_cha_id==0) // { // pUnpackEvent->ffGammaE[0]=(-1.)*ampl/20.-(-1.)*baseline/20.; // // } // h_peak [l_sfp_id][l_feb_id][l_cha_id]->Fill (2.*h_mwd_f[l_sfp_id][l_feb_id][l_cha_id]->GetMinimum ()); } } } } //end moving window filter } if (l_fpga_filt_on_off == 1) // trace AND fpga filter data { for (l_l = 0; l_l < (l_trace_size >> 1); l_l++) // loop over traces { // disentangle data l_dat_trace = *pl_tmp++; l_dat_filt = *pl_tmp++; l_filt_sign = (l_dat_filt & 0x800000) >> 23; #ifdef USE_MBS_PARAM l_adc_type = (l_trace_head & 0x800000) >> 23; #else l_adc_type = (l_sfp_adc_type[l_sfp_id] >> l_feb_id) & 0x1; #endif if (l_adc_type == 0) // 12 bit { l_dat_trace = l_dat_trace & 0xfff; } if (l_adc_type == 1) // 14 bit { l_dat_trace = l_dat_trace & 0x3fff; } l_dat_filt = l_dat_filt & 0x7fffff; if (l_filt_sign == 1) { l_dat_filt = l_dat_filt * -1; } // h_trace [l_sfp_id][l_feb_id][l_cha_id]->SetBinContent (l_l+1, l_dat_trace); // h_trapez_fpga[l_sfp_id][l_feb_id][l_cha_id]->SetBinContent (l_l+1, l_dat_filt); h_trace[l_sfp_id][l_feb_id][l_cha_id]->SetBinContent(l_l, l_dat_trace); // h_trace[l_sfp_id][l_feb_id][l_cha_id]->SetBinContent (l_l, l_dat_filt); l_tr[l_l] = l_dat_trace; } l_trace_size = l_trace_size >> 1; } // find base line value of trace and correct it to baseline 0 f_bls_val = 0.; for (l_l = l_bls_start; l_l < l_bls_stop; l_l++) { f_bls_val += (Double_t) l_tr[l_l]; } f_bls_val = f_bls_val / (Double_t) (l_bls_stop - l_bls_start); for (l_l = 0; l_l < l_trace_size; l_l++) // create baseline restored trace { f_tr_blr[l_l] = (Double_t) l_tr[l_l] - f_bls_val; h_trace_blr[l_sfp_id][l_feb_id][l_cha_id]->Fill(l_l, f_tr_blr[l_l]); h_trace_blr[l_sfp_id][l_feb_id][l_cha_id]->SetBinContent(l_l + 1, f_tr_blr[l_l]); } // find peak and fill histogram // h_peak [l_sfp_id][l_feb_id][l_cha_id]->Fill (h_trace[l_sfp_id][l_feb_id][l_cha_id]->GetMaximum ()); // h_valley[l_sfp_id][l_feb_id][l_cha_id]->Fill (h_trace[l_sfp_id][l_feb_id][l_cha_id]->GetMinimum ()); } #endif #ifdef Trace_Off // jump over trace pl_tmp += (l_cha_size >> 2) - 2; #endif // trace trailer //printf ("trace trailer \n"); l_trace_trail = *pl_tmp++; if (((l_trace_trail & 0xff000000) >> 24) != 0xbb) { printf("ERROR>> trace trailer id is not 0xbb, "); printf("SFP: %d, FEB: %d, CHA: %d \n", l_sfp_id, l_feb_id, l_cha_id); goto bad_event; } } } else { printf("ERROR>> data word neither channel header nor padding word \n"); } } #ifdef Histo_On for (l_i = 0; l_i < MAX_SFP; l_i++) { if (l_sfp_slaves[l_i] != 0) { for (l_j = 0; l_j < l_sfp_slaves[l_i]; l_j++) { for (l_k = 0; l_k < N_CHA; l_k++) { h_ch_hitpat[l_i][l_j][l_k]->Fill(l_ch_hitpat[l_i][l_j][l_k]); h_ch_hitpat_tr[l_i][l_j][l_k]->Fill(l_ch_hitpat_tr[l_i][l_j][l_k]); } } } } #endif bad_event: ; } } //close subevent-loop //++++++++++++++++++++++++++++++ } // end: ; } //close void Unpack void TascaUnpackProc::f_make_histo(Int_t l_mode) { TString obname; TString obtitle; UInt_t l_i, l_j, l_k; UInt_t l_tra_size; UInt_t l_trap_n_avg; UInt_t l_left; UInt_t l_right; #ifdef USE_MBS_PARAM l_tra_size = l_trace & 0xffff; l_trap_n_avg = l_e_filt >> 21; printf("f_make_histo: trace size: %d, avg size %d \n", l_tra_size, l_trap_n_avg); fflush(stdout); l_sfp_slaves[0] = l_slaves & 0xff; l_sfp_slaves[1] = (l_slaves & 0xff00) >> 8; l_sfp_slaves[2] = (l_slaves & 0xff0000) >> 16; l_sfp_slaves[3] = (l_slaves & 0xff000000) >> 24; printf("f_make_histo: # of sfp slaves: 3:%d, 2:%d, 1: %d, 0: %d \n", l_sfp_slaves[3], l_sfp_slaves[2], l_sfp_slaves[1], l_sfp_slaves[0]); fflush(stdout); #else l_tra_size = TRACE_SIZE; l_trap_n_avg = TRAPEZ_N_AVG; #endif // USE_MBS_PARAM #ifdef Histo_On for (l_i = 0; l_i < MAX_SFP; l_i++) { if (l_sfp_slaves[l_i] != 0) { for (l_j = 0; l_j < l_sfp_slaves[l_i]; l_j++) { for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/Traces/TRACE SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("Trace"); h_trace[l_i][l_j][l_k] = MakeTH1('I', obname.Data(), obtitle.Data(), l_tra_size, 0, l_tra_size); } for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/Traces BLR/TRACE, base line restored SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("Trace, base line restored"); h_trace_blr[l_i][l_j][l_k] = MakeTH1('F', obname.Data(), obtitle.Data(), l_tra_size, 0, l_tra_size); } for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/FPGA/FPGA Trapez SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("FPGA Trapez"); h_trapez_fpga[l_i][l_j][l_k] = MakeTH1('F', obname.Data(), obtitle.Data(), l_tra_size, 0, l_tra_size); } for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/FPGA/FPGA Energy(hitlist) SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("FPGA Energy"); l_right = 0x1000 * l_trap_n_avg; l_left = -1 * l_right; //printf ("depp: %d %d\n", l_left, l_right); fflush (stdout); h_fpga_e[l_i][l_j][l_k] = MakeTH1('F', obname.Data(), obtitle.Data(), 0x1000, l_left, l_right); // h_fpga_e[l_i][l_j][l_k] = MakeTH1('F', obname.Data(),obtitle.Data(),100000,-400000,2000000); } for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/Peaks/PEAK SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("Peak"); h_peak[l_i][l_j][l_k] = MakeTH1('I', obname.Data(), obtitle.Data(), 16000, 0., 16000.); } //added baatar for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/MWF/AMP SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("Ampl"); h_mwd_f[l_i][l_j][l_k] = MakeTH1('I', obname.Data(), obtitle.Data(), l_tra_size, 0, l_tra_size); } //end baatar for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/Valleys/VALLEY SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("Valley"); h_valley[l_i][l_j][l_k] = MakeTH1('I', obname.Data(), obtitle.Data(), 0x1000, 0, 0x4000); } for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/Timediff/Trigger time - Hit time SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("TRIG-HIT"); h_trgti_hitti[l_i][l_j][l_k] = MakeTH1('I', obname.Data(), obtitle.Data(), 2000, -1000, 1000); } for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/Hitpat_Cha_List/Channel hit pattern per event (list) SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("HITPAT_Cha_List"); h_ch_hitpat[l_i][l_j][l_k] = MakeTH1('I', obname.Data(), obtitle.Data(), 11, -1, 10); } for (l_k = 0; l_k < N_CHA; l_k++) { obname.Form("Unpack/Hitpat_Cha_Trace/Channel hit pattern per event (trace) SFP: %2d FEBEX: %2d CHAN: %2d", l_i, l_j, l_k); obtitle.Form("HITPAT_Cha_Trace"); h_ch_hitpat_tr[l_i][l_j][l_k] = MakeTH1('I', obname.Data(), obtitle.Data(), 11, -1, 10); } obname.Form("Unpack/Hitpat_Feb_List/Hit Pattern (list) SFP: %2d FEBEX: %2d", l_i, l_j); obtitle.Form("Hitpat_List"); h_hitpat[l_i][l_j] = MakeTH1('I', obname.Data(), obtitle.Data(), 20, -2, 18); obname.Form("Unpack/Hitpat_Feb_Trace/Hit Pattern (trace) SFP: %2d FEBEX: %2d", l_i, l_j); obtitle.Form("Hitpat_Trace"); h_hitpat_tr[l_i][l_j] = MakeTH1('I', obname.Data(), obtitle.Data(), 20, -2, 18); } } } #endif }