#include "rootspy_hist.hh" #include #include #include //using namespace evio; using namespace std; static Hist *hist ; static int event_f250; static int time_f250; static int event_write; static FILE *RunFile; static int INIT = 0; //static TCanvas *c0; extern int Debug; extern int Debug_Slot; extern int Debug_Chan; // stty -tostop // debugger gdb //--------------------------------------------------------------------------- int str2int (std::string ss, int base) { //---- !!!! -1 !!!! error code !!!! char *end; long l; const char *s=ss.c_str(); errno = 0; l = strtol(s, &end, base); if (errno == ERANGE) { printf("ERROR::str2int ERANGE:: %s \n",s); return -1; } if (*s == '\0' || *end != '\0') { printf("\n **** ERROR:: str2int INCONVERTIBLE:: %s \n",s); return -1; } return l; } //----------------------------------------------------- vector Parsing(string s, string delim) { std::vector parsed; //string s = "roccdc2_F125_05_02" ; //h1->GetName(); // roccdc2_F125_05_02 roccdc1_F125_04_02 //string delim = "_"; size_t start = 0U; size_t end = s.find(delim); int nparam=0; if (Debug>1) std::cout << "Parsing , delim=" << delim << "," <1) std::cout << "nparam =" << nparam << " name=:" << s.substr(start, end - start) << ":"<1) std::cout << "nparam =" << nparam << " name=:" << s.substr(start, end ) << ":"<1) std::cout << "Number nparams = " << nparam <shmem_ptr=shmem_ptr; hist->hrol1 = shmem_ptr->H_rol1; printf(" shmem_ptr=%p \n",hist->shmem_ptr,INIT); return hist; } //----------------------------------------------------- int reset_hist(int runnum, int flag) { for (int il=0; il<5; il++) { printf("INFO:::: Reset all histos ... runnum=%d flag=%d INIT=%d\n",runnum,flag,INIT); if (INIT>0) { hist->Reset_Hist(runnum, flag); break; } sleep(1); } } //----------------------------------------------------- int fill_hist() { //printf("Hptr2 = %p \n",hist); hist->test_fill(); } //----------------------------------------------------- int fill_ped(int ped) { hist->ped_fill(ped); } //----------------------------------------------------- int fill_fadc(int slot, int chan, int adc ) { //printf("fill_fadc:: slot=%d chan=%d, adc=%d \n",slot, chan, adc); hist->Fill_F250_adc(slot,chan,adc); } //----------------------------------------------------- int fill_f250_scalers(int slot, int chan, double rate ) { //printf("fill_fadc:: slot=%d chan=%d, adc=%d \n",slot, chan, adc); hist->Fill_F250_Scalers(slot,chan,rate); } //----------------------------------------------------- int fill_discr_scalers(int slot, int chan, double rate ) { //printf("fill_fadc:: slot=%d chan=%d, adc=%d \n",slot, chan, adc); hist->Fill_DISCR_Scalers(slot,chan,rate); } //----------------------------------------------------- int fill_discr_slots(int Nsl, int *slots) { hist->Nslots=Nsl; if (Debug>0) printf("Found N DISCRs=%d in slots: ",Nsl); for (int ii=0; ii=21) break; hist->Dslots[ii]=slots[ii]; if (Debug>0) printf(" %d ",slots[ii]); } if (hist->ROOT_WRITE_LOCK==0) hist->Tdsc->Fill(); if (Debug>0) printf("Lock=%d, sizeof():: %d %d %d %d\n" ,hist->ROOT_WRITE_LOCK,sizeof(time_t),sizeof(unsigned int),sizeof(unsigned long long),sizeof(double)); } //----------------------------------------------------- int fill_discr_time(double time) { if (time<0) return 1; for (int ii=0; iiNslots; ii++) { if (Debug>5) printf("Fill DscRate(1); Dtime=%f i=%d, sl=%d rate: ",time, ii, hist->Dslots[ii] ); for (int ch=0; ch<16; ch++) { hist->DscRate[ii][ch]=hist->DscRate[hist->Dslots[ii]][ch]; if (Debug>5) { printf(" %4.1e:%4.1e",hist->DscRate[ii][ch], hist->DscRate[ii][ch]); }; }; if (Debug>5) printf("\n"); } hist->Dtime=time; if (hist->ROOT_WRITE_LOCK==0 && hist->Nslots>0) hist->Trate->Fill(); if (Debug>0) { printf("Fill Trate(); Dtime=%f Nslots=%d file=%p ",time,hist->Nslots,hist->Trate->GetCurrentFile()); if (hist->Trate->GetCurrentFile()) printf("Name=%s \n",hist->Trate->GetCurrentFile()->GetName() ); else printf("\n"); } return 0; } //----------------------------------------------------- int fill_dirc_scalers(int slot, int fiber, int chan, double rate ) { if ((Debug>0 && rate>0) || chan==0) printf("fill_dirc_scalers:: slot=%d fiber=%d chan=%d, rate=%f \n",slot, fiber, chan, rate); hist->Fill_DIRC_Scalers(slot-DIRC_FIRST_SLOT,fiber,chan,rate); } //----------------------------------------------------- int fill_dirc_data(int slot, int fiber, int chan, uint64_t data ) { if (chan==0) printf("fill_dirc_data:: slot=%d fiber=%d chan=%d, data=%f \n",slot, fiber, chan, data/1000.); hist->Fill_DIRC_Data(slot-DIRC_FIRST_SLOT, fiber, chan, data/1000.); } //----------------------------------------------------- // Reset DIRC //----------------------------------------------------- int reset_dirc_scalers(int slot) { printf("reset_dirc_scalers slot=%d\n",slot); hist->Reset_DIRC_Scalers(slot-DIRC_FIRST_SLOT); } //----------------------------------------------------- int reset_dirc_data(int slot) { printf("reset_dirc_data slot=%d \n",slot); hist->Reset_DIRC_Data(slot-DIRC_FIRST_SLOT); } //----------------------------------------------------- int fill_dirc_time(double time) { if (time<0) return 1; /* for (int ii=0; iiNslots; ii++) { if (Debug>5) printf("Fill DscRate(1); Dtime=%f i=%d, sl=%d rate: ",time, ii, hist->Dslots[ii] ); for (int ch=0; ch<16; ch++) { hist->DscRate[ii][ch]=hist->DscRate[hist->Dslots[ii]][ch]; if (Debug>5) { printf(" %4.1e:%4.1e",hist->DscRate[ii][ch], hist->DscRate[ii][ch]); }; }; if (Debug>5) printf("\n"); } hist->Dtime=time; if (hist->ROOT_WRITE_LOCK==0 && hist->Nslots>0) hist->Trate->Fill(); if (Debug>0) { printf("Fill Trate(); Dtime=%f Nslots=%d file=%p ",time,hist->Nslots,hist->Trate->GetCurrentFile()); if (hist->Trate->GetCurrentFile()) printf("Name=%s \n",hist->Trate->GetCurrentFile()->GetName() ); else printf("\n"); } */ return 0; } //----------------------------------------------------- int fill_bank(unsigned int *bank, int size) { scan_bank(bank, size); } //----------------------------------------------------- int save_hists(int flag, int DAC) { hist->Save_Hists(flag, DAC); } //----------------------------------------------------- int fit_hist(int RUN_NUM, int DAC, int FADC, int *new_dac, int *new_thr, int max_dac) { //-- FADC:: 0=f125 , 1=f250 return hist->Fit_Hist(RUN_NUM,DAC,FADC,new_dac,new_thr,max_dac); } //----------------------------------------------------------------------------------------- // WRITE BUFFER //----------------------------------------------------------------------------------------- void write_bank(unsigned int *bank, int size) { //evioFileChannel *chan = (evioFileChannel*) bank; // create event tree and analyze //evioDOMTree eventTree(chan); // get list of all banks in event //evioDOMNodeListP bankList = eventTree->getNodeList(); char host_name[80]; gethostname(host_name, 80); event_write++; char name[128]; BankHeader Bank(bank); Bank.print(); RocHeader ROC_Header(bank); ROC_Header.print(); sprintf(name,"%s/EVENTS/event_%s_%d.evio",getenv("HOME"),host_name,event_write); printf("open file %s\n",name); int rc=0; if((RunFile = fopen(name,"w")) == NULL) { printf("Can not open file %s\n",name); } else { rc=fwrite(bank,4,size,RunFile); } if (RunFile) fclose(RunFile); RunFile=NULL; printf("close file rc=%d\n",rc); //int fd=open(name,O_WRONLY); //int rc = write(fd, bank, size*4); //close(fd); } //----------------------------------------------------------------------------------------- // Banks decoding //----------------------------------------------------------------------------------------- int scan_bank(unsigned int *buffer, int size) { if (Debug>8) write_bank(buffer, size); if (Debug>1) printf("----------------------> scan_bank():: new buffer <---------------------------\n"); BankHeader Bank(buffer); if (Debug>1) Bank.print(); RocHeader ROC_Header(buffer); if (Debug>1) ROC_Header.print(); buffer+=2; hist->EventSize->Fill(float(size*4./1024.)); hist->size2time->Fill(float(hist->shmem_ptr->VME_Size*4./1024.),float(hist->shmem_ptr->VME_Time)); unsigned i = 0; while (i < (size-2)) { if (Debug>1) printf("Loop:: i=%d size=%d\n",i,size-2); BankHeader Bank(buffer); if (Debug>1) Bank.print(); if ((Bank.Tag&0xFF00)==0xFF00) { //--- Trigger INFO TriggerHeader Trigger_Header(buffer); if (Debug>1) Trigger_Header.print(); if (Debug>1) printf(" .... Tag=0x%X, Skip %d words \n",Bank.Tag,Bank.Size+1); } else if (Bank.Tag==6) { //-- F250 event if (Debug>1) printf(" F250 event:: i=%d Tag=0x%X, size=%d (0x%X) words \n",i,Bank.Tag,Bank.Size,Bank.Size); if (Bank.Size<=size) analyzeBank_F250(buffer); else if (Debug>0) write_bank(buffer, size); } else if (Bank.Tag==20) { //-- CAEN TDC event if (Debug>1) printf(" CAEN TDC event:: i=%d Tag=0x%X, size=%d (0x%X) words \n",i,Bank.Tag,Bank.Size,Bank.Size); analyzeBank_CEAN_TDC(buffer); } else if (Bank.Tag == 16) { // F125 , FDC/CDC if (Debug>1) printf(" F125 event:: i=%d Tag=0x%X, size=%d (0x%X) words \n",i,Bank.Tag,Bank.Size,Bank.Size); if (Bank.Size<=size) analyzeBank_F125(buffer); else if (Debug>0) write_bank(buffer, size); } else if (Bank.Tag == 26) { // F1TDCs if (Debug>1) printf(" F1TDC event:: i=%d Tag=0x%X, size=%d (0x%X) words \n",i,Bank.Tag,Bank.Size,Bank.Size); if (Bank.Size<=size) analyzeBank_F1TDC(buffer); else if (Debug>0) write_bank(buffer, size); } buffer+=(Bank.Size+1); i+=(Bank.Size+1); } //-- end while } /* else if ( (ROC_Header.ID == 25) || // CDCs (ROC_Header.ID == 26) || (ROC_Header.ID == 27) || (ROC_Header.ID == 28) || (ROC_Header.ID == 52) || // FDCs (ROC_Header.ID == 53) || (ROC_Header.ID == 55) || (ROC_Header.ID == 56) || (ROC_Header.ID == 57) || (ROC_Header.ID == 58) || (ROC_Header.ID == 59) || (ROC_Header.ID == 60) || (ROC_Header.ID == 61) || (ROC_Header.ID == 62)) { */ //----------------------------------------------------------------------------------------- int analyzeBank_CEAN_TDC(unsigned int *buffer) { #define CAEN_GLOB_HEAD 8 #define EVT_COUNT 0x7FFFFD0 #define GEO 0x1F #define CAEN_GLOB_TRAIL 16 BankHeader Bank(buffer); if (Debug>1) Bank.print(); int bank_size=Bank.Size-1; unsigned int *bank = (buffer+2); if (Debug>1) printf("CAEN_TDC:: bank ptr = %p size=%d\n",bank, bank_size); if (bank_size<=0) return 0; if (Debug>1) printf("CAEN_TDC:: H0=0x%08X H1=0x%08X \n",*bank,*(bank+1)); if (Debug>1) fflush(stdout); int debug = 0; //const vector *vec = bankPtr->getVector(); //if(vec == NULL) {cerr << "?unable to get tdc bank vector" << endl; return;} // if(debug) cout << " CAEN1290 TDC BANK FOUND " << vec->size() << " Event number " << (*vec)[0] << endl; int global_head = 0; int event_count = -1; int caen_slot = -1; unsigned int tdc_channel; unsigned int tdc_time; unsigned int tdc_channel_old=-1; unsigned int tdc_time_old = -1; int caen_slot_old = -1; for (unsigned i = 0; i < bank_size; i++){ bswap(&bank[i]); if( (bank[i] >> 27) == CAEN_GLOB_HEAD){ if(global_head != 0){ cout << "CEAN_TDC:: FATAL: Missing global trailer " << endl; return 1; } event_count = (bank[i] & EVT_COUNT) >> 5; if(debug) cout << "CEAN_TDC:: EVENT COUNT = " << event_count << endl; caen_slot = (bank[i] & GEO); if(debug) cout << "CEAN_TDC:: SLOT = " << caen_slot << endl; global_head = 1; } if( (bank[i] >> 27) == CAEN_GLOB_TRAIL){ if(global_head != 1){ cout << " FATAL: Missing global header " << endl; return 1; } global_head = 0; } if( (bank[i] >> 27) == 1){ unsigned int tdc = (bank[i] & 0x3000000) >> 23; // if(debug) cout << " TDC header found " << " TDC = " << tdc << " i = " << i << endl; } // TDC measurement if( (bank[i] >> 27) == 0){ tdc_channel = (bank[i] & 0x3E00000) >> 21; unsigned int tdc_time = (bank[i] & 0x1FFFFF); if (Debug>0) cout << " Slot " << caen_slot << " TDC channel " << tdc_channel << " TDC time = " << tdc_time << endl; if (0<=caen_slot && caen_slot < 21 && 0<=tdc_channel && tdc_channel<32) { //-- fill hist --- hist->Fill_CAEN(caen_slot,tdc_channel,tdc_time); if (caen_slot==caen_slot_old && tdc_channel==tdc_channel_old) { if (caen_slot==8 && tdc_channel==31) hist->tdc_rf_f1tdc->Fill(float(tdc_time-tdc_time_old)); if (Debug>0) cout << " Slot " << caen_slot << " TDC channel " << tdc_channel << " TDC time = " << tdc_time << " dt = " << tdc_time-tdc_time_old << endl; } caen_slot_old=caen_slot; tdc_channel_old=tdc_channel; tdc_time_old=tdc_time; } } } //-- end for --- } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- uint32_t F1TDC_channel(uint32_t chip, uint32_t chan_on_chip, int modtype) { /// Convert a F1TDC chip number and channel on the chip to the /// front panel channel number. This is based on "Input Channel Mapping" /// section at the very bottom of the document F1TDC_V2_V3_4_29_14.pdf const int F1TDC32 = 3; const int F1TDC48 = 4; uint32_t channel_map[8] = {0, 0, 1, 1, 2, 2, 3, 3}; switch(modtype){ case F1TDC32: return (4 * chip) + channel_map[ chan_on_chip&0x7 ]; case F1TDC48: return (chip <<3) | chan_on_chip; default: printf("F1TDC_channel called for non-F1TDC module type\n"); } return 1000000; // (should never get here) } #if 0 //-------------------------------------------------------------------------------------------------- // ParseF1TDCBank //---------------- int analyzeBank_F1TDC(unsigned int *buffer) { #define VERBOSE 9 //------------------------------------------------------------ BankHeader Bank(buffer); if (Debug>1) Bank.print(); //int bank_size=size; int bank_size=Bank.Size-1; unsigned int *bank = (buffer+2); if (Debug>1) printf("F1TDC:: bank ptr = %p size=%d\n",bank, bank_size); if (bank_size<=0) return 0; if (Debug>1) printf("F1TDC:: H0=0x%08X H1=0x%08X \n",*bank,*(bank+1)); if (Debug>1) fflush(stdout); //------------------------------------------------------------ //void DEVIOWorkerThread::ParseF1TDCBank(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) char host_name[80]; gethostname(host_name, 80); unsigned char* word; uint32_t* iptr = buffer; uint32_t *istart = iptr; //auto pe_iter = current_parsed_events.begin(); //DParsedEvent *pe = NULL; uint32_t slot = 0; uint32_t modtype = 0; uint32_t itrigger = -1; uint32_t trig_time_f1header = 0; for (unsigned i = 0; i < bank_size; i++){ word=(unsigned char*)&bank[i]; unsigned char byte; // swap byte=word[0]; word[0]=word[3]; word[3]=byte; byte=word[1]; word[1]=word[2]; word[2]=byte; // Loop over data words //for(; iptr>31) & 0x1) == 0)continue; uint32_t data_type = (*iptr>>27) & 0x0F; switch(data_type){ case 0: // Block Header slot = (*iptr)>>22 & 0x001F; modtype = (*iptr)>>18 & 0x000F; // should match a DModuleType::type_id_t if(VERBOSE>7) cout << " F1 Block Header: slot=" << slot << " modtype=" << modtype << endl; break; case 1: // Block Trailer //pe_iter = current_parsed_events.begin(); //pe = NULL; if(VERBOSE>7) cout << " F1 Block Trailer" << endl; break; case 2: // Event Header { //pe = *pe_iter++; itrigger = (*iptr)>>0 & 0x0003FFFFF; if(VERBOSE>7) { uint32_t slot_event_header = (*iptr)>>22 & 0x00000001F; cout << " F1 Event Header: slot=" << slot_event_header << " itrigger=" << itrigger << endl; } } break; case 3: // Trigger time { uint64_t t = ((*iptr)&0xFFFFFF)<<0; iptr++; if(((*iptr>>31) & 0x1) == 0){ t += ((*iptr)&0xFFFFFF)<<24; // from word on the street: second trigger time word is optional!!?? }else{ iptr--; } if(VERBOSE>7) cout << " F1TDC Trigger Time (t="<NEW_DF1TDCTriggerTime(rocid, slot, itrigger, t); } break; case 8: // F1 Chip Header trig_time_f1header = ((*iptr)>> 7) & 0x1FF; if(VERBOSE>7) { uint32_t chip_f1header = ((*iptr)>> 3) & 0x07; uint32_t chan_on_chip_f1header = ((*iptr)>> 0) & 0x07; // this is always 7 in real data! uint32_t itrigger_f1header = ((*iptr)>>16) & 0x3F; cout << " Found F1 header: chip=" << chip_f1header << " chan=" << chan_on_chip_f1header << " itrig=" << itrigger_f1header << " trig_time=" << trig_time_f1header << endl; } break; case 7: // F1 Data { uint32_t chip = (*iptr>>19) & 0x07; uint32_t chan_on_chip = (*iptr>>16) & 0x07; uint32_t time = (*iptr>> 0) & 0xFFFF; uint32_t channel = F1TDC_channel(chip, chan_on_chip, modtype); if(VERBOSE>7) cout << " Found F1 data : chip=" << chip << " chan=" << chan_on_chip << " time=" << time << " channel=" << channel << endl; //if(pe){ // auto hit = pe->NEW_DF1TDCHit(rocid, slot, channel, itrigger, trig_time_f1header, time, *iptr, MODULE_TYPE(modtype)); // if(hit->res_status==0){ // static uint32_t Nwarnings=0; // if(Nwarnings<10) jerr << "ERROR: F1 TDC chip \"unlocked\" flag set!" << ((++Nwarnings == 10) ? " -- last warning":"") << endl; // } // } } break; case 15: // Filler word if(VERBOSE>7) cout << " F1 filler word" << endl; case 14: // Data not valid (how to handle this?) break; default: cerr<"; break; default: break; } cerr< (iptr+4)) break; } */ //throw JException("Unexpected word type in F1TDC block!", __FILE__, __LINE__); break; } } // Skip filler words //while(iptr RFt; int analyzeBank_F1TDC(unsigned int *buffer) { //------------------------------------------------------------ BankHeader Bank(buffer); if (Debug>1) Bank.print(); //int bank_size=size; int bank_size=Bank.Size-1; unsigned int *bank = (buffer+2); if (Debug>1) printf("F1TDC:: bank ptr = %p size=%d\n",bank, bank_size); if (bank_size<=0) return 0; if (Debug>1) printf("F1TDC:: H0=0x%08X H1=0x%08X \n",*bank,*(bank+1)); if (Debug>1) fflush(stdout); //------------------------------------------------------------ #define F1_BLOCK_HEAD 16 #define F1_BLOCK_TRAIL 17 #define F1_EVENT_HEAD 18 #define F1_TRIG_TIME 19 #define F1_MEAS 23 #define F1_CHIP_HEAD 24 #define F1_NOT_VALID 30 #define F1_FILLER 31 #define F1_SLOT 0x7C00000 #define F1_ID 0x3C0000 #define F1_BLOCK 0x3FF00 #define F1_NEVT_BLOCK 0xFF #define F1_TRIG_NUMB 0x3FFFFF #define F1_TDE 0xFFFF #define F1_CHIP 0x380000 #define F1_CHAN 0x70000 #define F1_TIME 0xFFFF int debug_tdc = 1; debug_tdc = Debug; int block_head = 0; int slot = -1; int mod_id = -1; int block_numb = -1; int nevt_block = -1; int trig_numb = -1; int trig_time = -1; int chip_stat = -1; int hit_fifo_over = -1 ; int out_fifo_over = -1; int chip_numb = -1; int chip_chan = -1; int channel = -1; int time_h = -1; int ch_tmp = -1; int slot_old=-1; int channel_old=-1; int time_h_old=-1; char host_name[80]; gethostname(host_name, 80); unsigned char* word; //std::vector RFt; time_t t_n = time(NULL); if ((t_n % 60)==0) { hist->tdc_occup2D_f1tdc->Reset(); /*hist->f125_occup2D->Reset();*/ } for (unsigned i = 0; i < bank_size; i++){ word=(unsigned char*)&bank[i]; unsigned char byte; // swap byte=word[0]; word[0]=word[3]; word[3]=byte; byte=word[1]; word[1]=word[2]; word[2]=byte; if( (bank[i] >> 27) == F1_BLOCK_HEAD){ if(block_head != 0){ cout << " FATAL: Missing global trailer " << endl; // exit(EXIT_FAILURE); } slot = (bank[i] & F1_SLOT) >> 22; // F1_SLOT 0x7C00000 mod_id = (bank[i] & F1_ID) >> 18; // F1_ID 0x3C0000 block_numb = (bank[i] & F1_BLOCK) >> 8; // F1_BLOCK 0x3FF00 nevt_block = (bank[i] & F1_NEVT_BLOCK); // F1_NEVT_BLOCK 0xFF if(debug_tdc) cout << " BLOCK HEADER " << " SLOT = " << slot << " ID = " << mod_id << " BLOCK NUMBER = " << block_numb << " NEVT_BLOCK = " << nevt_block << endl; block_head = 1; } if( (bank[i] >> 27) == F1_EVENT_HEAD){ slot = (bank[i] & F1_SLOT) >> 22; trig_numb = (bank[i] & F1_TRIG_NUMB); if(debug_tdc) cout << " EVENT HEADER " << " SLOT = " << slot << " Trigger number = " << trig_numb << " RFt.size=" << RFt.size() <1) { //cout << "orig: "; for (vector::iterator it=RFt.begin(); it!=RFt.end(); ++it) { cout << *it << " "; } cout << endl; std::sort (RFt.begin(), RFt.end()); //cout << "sort: "; for (vector::iterator it=RFt.begin(); it!=RFt.end(); ++it) { cout << *it << " "; } cout << endl; for (int i=1; itdc_rf_f1tdc->Fill(float(RFt[i]-RFt[i-1])); //printf(" %d,%d,%d ",RFt[i-1],RFt[i],RFt[i]-RFt[i-1]); } //cout << endl; } RFt.clear(); //---------------------------------------------------------------------------------------- } // Trigger Time if( (bank[i] >> 27) == F1_TRIG_TIME){ trig_time = (bank[i] & F1_TDE); // F1_TDE 0xFFFF if(debug_tdc) cout << " TRIGGER TIME DE " << trig_time << endl; } if( (bank[i] >> 27) == 0){ trig_time = (bank[i] & F1_TDE); if(debug_tdc) cout << " TRIGGER TIME AB " << trig_time << "byte=" << i << " of " << bank_size << endl; } if( (bank[i] >> 27) == F1_MEAS){ //low resolution TDC data and channel number decoding: //chip = ((*vec)[k]>>19) & 0x7; //channel = ((*vec)[k]>>16) & 0x7; //time_h = (*vec)[k] & 0xffff; //TDCchannel = 8*chip + channel; chip_stat = ((bank[i] >> 26) & 0x1); hit_fifo_over = ((bank[i] >> 25) & 0x1); out_fifo_over = ((bank[i] >> 24) & 0x1); chip_numb = ( bank[i] & F1_CHIP) >> 19 ; // F1_CHIP 0x380000 chip_chan = ( bank[i] & F1_CHAN) >> 16 ; // F1_CHAN 0x70000 time_h = ( bank[i] & F1_TIME); // F1_TIME 0xFFFF ch_tmp = -1; if( (chip_chan == 0) || (chip_chan == 1)) ch_tmp = 0; if( (chip_chan == 2) || (chip_chan == 3)) ch_tmp = 1; if( (chip_chan == 4) || (chip_chan == 5)) ch_tmp = 2; if( (chip_chan == 6) || (chip_chan == 7)) ch_tmp = 3; // if( (ch_tmp >= 0) && (ch_tmp < 4) ){ // --- high resol TDC // channel = chip_numb*4 + ch_tmp; // } //if( (chip_chan >= 0) && (chip_chan < 8) ){ // low res TDC //channel = chip_numb*8 + chip_chan; //} channel=F1TDC_channel(chip_numb,chip_chan,mod_id); if(debug_tdc) cout << " HITS: " << " Chip status = " << chip_stat << " Hit FIFO over = " << hit_fifo_over << " Out FIFO over " << out_fifo_over << endl; if(debug_tdc) cout << " Chip = " << chip_numb << " Chip Chan = " << chip_chan << " Channel = " << channel << " Time = " << time_h << endl; if(debug_tdc) printf("slot=%d, channel=%d, time_h=%d (%d,%d,%d) dt=%.1f\n",slot,channel,time_h,slot_old,channel_old,time_h_old,float(time_h-time_h_old)); //printf(" host name = %s \n",host_name); if (0<=slot && slot<21 && 0<=channel && channel<64) { hist->Fill_F1TDC(slot, channel, time_h); if (strncmp(host_name,"rocfdc1",7)==0 && slot==17 && channel==31) { RFt.push_back(time_h); } if (strncmp(host_name,"rocstpsc1",9)==0 && slot==4 && channel==31) { RFt.push_back(time_h); } if (strncmp(host_name,"roctagmh",8)==0 && slot==16 && channel==31) { RFt.push_back(time_h); } //printf(" host name = %s slot=% chan=%d RFt.size=%d \n",host_name,slot,channel,RFt.size()); //if (slot==slot_old && channel==channel_old) { //printf("1 RTF size=%d\n",RFt.size()); /* if (slot!=slot_old || channel!=channel_old) { printf("2 RTF size=%d\n",RFt.size()); if ( RFt.size()>1) { cout << "orig: "; for (vector::iterator it=RFt.begin(); it!=RFt.end(); ++it) { cout << *it << " "; } cout << endl; std::sort (RFt.begin(), RFt.end()); cout << "sort: "; for (vector::iterator it=RFt.begin(); it!=RFt.end(); ++it) { cout << *it << " "; } cout << endl; for (int i=1; itdc_rf_f1tdc->Fill(float(RFt[i]-RFt[i-1])); } cout << endl; RFt.clear(); } } */ slot_old=slot; channel_old=channel; time_h_old=time_h; } } if( (bank[i] >> 27) == F1_BLOCK_TRAIL){ if(block_head != 1){ cout << " FATAL: Missing global header " << endl; // exit(EXIT_FAILURE); } block_head = 0; } } // Loop over TDC data words /* jana uint32_t data_type = (*iptr>>27) & 0x0F; switch(data_type){ case 0: // Block Header slot = (*iptr)>>22 & 0x001F; modtype = (*iptr)>>18 & 0x000F; // should match a DModuleType::type_id_t ------------------------ Lubomir for (unsigned int k=0; ksize();k++){ if (((*vec)[k]>>27) == 0x12){ eventNum = (*vec)[k] & 0x3fffff; slot = ((*vec)[k]>>22) & 0x1f; } if (((*vec)[k]>>27) == 0x17){ chip = ((*vec)[k]>>19) & 0x7; channel = ((*vec)[k]>>16) & 0x7; time_h = (float)((*vec)[k] & 0xffff); int ch = 8*chip + (channel); } } -------------------------------bcal3-------------------------------------------- f1TDC Chip Configuration Bin Full Rollover Slot Chip Rez PL PTW Size Range Count -------------------------------------------------------------------------------- 3 ALL High 400.0 3400.0 0.0581 3806.1 64466 4 ALL High 400.0 3400.0 0.0581 3806.1 64466 */ } #endif //----------------------------------------------------------------------------------------- int analyzeBank_F250(unsigned int *buffer) { BankHeader Bank(buffer); if (Debug>1) Bank.print(); //#define FA250_FE_CONFIG1_MODE_MASK 0x00000007 //int F250_mode = hist->shmem_ptr->BOR.f250[3].fe[1].config1 & FA250_FE_CONFIG1_MODE_MASK; event_f250++; //----------------------------------------------------------------------------- if ((time(NULL)-time_f250)>100) { event_f250=0; time_f250=time(NULL); //--- 100 sec. FIT and reset pedestal monitor histos --- hist->Fit_PedMon(); } //----------------------------------------------------------------------------- //int bank_size=size; int bank_size=Bank.Size-1; unsigned int *bank = (buffer+2); if (Debug>1) printf("F250:: bank ptr = %p size=%d\n",bank, bank_size); if (bank_size<=0) return 0; if (Debug>1) printf("F250:: H0=0x%08X H1=0x%08X \n",*bank,*(bank+1)); if (Debug>1) fflush(stdout); //hist->f250_scalers_fill(100); const int Plen=hist->f250_pulse_len; const int Pthr=120; int pulse_cnt=0, pulse_thr=Pthr, pulse_max1=0, pulse_max2=0, pulse_ped=0, pulse_data[Plen], pulse_sl=0, pulse_ch=0; for (int ii=0; ii>31) & 0x1) == 0) continue; // raw data problem // Bank header // bit 31 = 1 // bits 27- 30 = 0 // bits 22 - 26 = SlotID // bits 11 - 21 = Number of events in block; bits 0 - 10 event block number if( bank[i] >> 27 == 0x10) /* Bank header 1000 0 */ { SlotID = (bank[i] & 0x7c00000) >> 22; if(debug_fadc) cout << " F250 found in slot: " << SlotID << endl; continue; } // Event header // bit 31 = 1 // bits 27- 30 = 0x1001 // bits 0 - 26 = Trigger number if( bank[i] >> 27 == 0x12) /* Event header 1001 0 */ { // trigger_numb[nboard] = (bank[i] & 0x7FFFFFF); if(debug_fadc) cout << " F250 Trigger time " << endl; i++; // remove word 2 continue; } if( bank[i] >> 27 == 0x13) /* Trigger time */ { if(debug_fadc) cout << " F250 found in slot: " << SlotID << " Trigger time " << (bank[i] & 0x7FFFFFF) << endl; continue; } if( bank[i] & 0x80000000 ) /* data type defining word */ { data_type = (bank[i] & 0x78000000) >> 27; // data_type == 4 - window raw data // data_type == 6 - pulse raw data data_new_type = 1; } else { data_new_type = 0; }; //cout << " Data type = " << data_type << endl; #if 1 // WINDOW RAW DATA if(data_type == 4 ) { int raw_debug = 0; if(data_new_type == 1){ if (hist->shmem_ptr->RUN_Flag==0) { //--- fill previous channel ampl -- if((0<=SlotID) && (SlotID<21) && (channel >= 0) && (channel < 16)) { hist->Fill_F250_adc(SlotID,channel,pulse_max2); } } fadc_raw_wind_width = (bank[i] & 0xFFF); channel = (bank[i] & 0x7800000) >> 23; // cout << " Data Type = " << data_type << " Fadc_width = " << fadc_width << " Channel = " << channel << endl; //------------------------------------------------------------------------- if (pulse_max2>pulse_max1) { //-------------------- fill pulse shape ----- pulse_max1=pulse_max2; for (int ii=0; iif250_pulse->SetBinContent(ii+1,pulse_data[ii]); hist->f250_pulse->SetEntries(pulse_sl*100+pulse_ch); if (pulse_ch>16) cout << " fa250 ERROR Fill channel = " << pulse_ch << endl; } for (int ii=0; ii= 0) && (channel < 16)){ if (hist->shmem_ptr->RUN_Flag!=0) { //--- fill pedestals ---- hist->Fill_F250_adc(SlotID,channel,adc_1); hist->Fill_F250_adc(SlotID,channel,adc_2); } pulse_sl=SlotID; pulse_ch=channel; if (0<=pulse_cnt && pulse_cntpulse_max2) pulse_max2=adc_1; } if (adc_1>pulse_thr) { hist->f250_time->Fill(float(pulse_cnt)); pulse_thr=1000000; } if (0<=pulse_cnt && pulse_cntpulse_max2) pulse_max2=adc_2; } if (adc_2>pulse_thr) { hist->f250_time->Fill(float(pulse_cnt)); pulse_thr=1000000; } } else {cout << " Wrong slot/channel number(4) slot=" << SlotID << " channel =" << channel << endl;} time_stamp++; } } // Data type 4, raw window data #endif int pulse_debug = 0; if (data_type == 0) { // block header nevtblk= bank[i] & 0x7F; ievtblk= bank[i]>>8 & 0x7F; if (m7debug>0 ) cout << "-----------------> fa250:: data type= " << data_type << " sl=" << SlotID << " nevt=" << nevtblk << endl; } if (data_type == 2) { // event header eventnr=bank[i] & 0x1FFFFF; } if (data_type == 3) { // trigger time if(data_new_type == 1) { //-- word 1 } else { //-- word 2 } } //cout << "fa250:: data type= " << data_type << " sl=" << SlotID << " chan=" << channel << " nevt=" << nevtblk << "," << eventnr << endl; /* //----------------------------------------------------------------------------------------------------------------------------------------- // Pulse Integral data if(data_type == 7 ) { channel = (bank[i] & 0x7800000) >> 23; unsigned int pulse_number = (bank[i] & 0x200000) >> 21; unsigned int pulse_int = (bank[i] & 0x3FFFF); } //----------------------------------------------------------------------------------------------------------------------------------------- // Pulse Time data if(data_type == 8 ){ unsigned int channel = (bank[i]>>23) & 0x0F; unsigned int pulse_number = (bank[i]>>21) & 0x03; adc_time0 = ( bank[i] & 0x7FC0) >> 6; if (m7debug>0 ) cout << "fa250::sl=" << SlotID << " chan=" << channel << " data type= " << data_type << " pulse=" << pulse_number << " pcnt=" << m7pcnt8 << " nevt=" << nevtblk << "," << eventnr << " t=" << adc_time0 << endl; if((0<=SlotID) && (SlotID<21) && (channel >= 0) && (channel < 16) && m7pcnt8<100 ){ //--- if (m7pcnt8<0) m7pcnt8=0; if (m7slot8<0) m7slot8=SlotID; if (m7chan8<0) m7chan8=channel; if (m7evnt8<0) m7evnt8=eventnr; if (m7slot8==SlotID && m7chan8==channel && 0<=m7pcnt8 && m7pcnt8<3 && m7evnt8==eventnr) { //-- same chan -- if (m7debug>6 ) cout << "fa250:: data type= " << data_type << " same " << endl; m7pnum8[m7pcnt8]=pulse_number; m7time[m7pcnt8]=adc_time0; } else { //-- next chan, fill old and reset ---- if (m7debug>0 ) cout << "fa250:: data type= " << data_type << " next " << m7slot8 << " " << SlotID << " " << m7chan8 << " " << channel << " " << m7pcnt8 << " " << m7evnt8 << " " << eventnr << endl; hist->f250_pulse->Fill(float(m7pcnt8)); m7pcnt8+=100; //--- wait for pulse_peak data --- m7slot8=SlotID; m7chan8=channel; m7evnt8=eventnr; } if (m7pcnt8<100) m7pcnt8++; //--- //hist->f250_time->Fill(float(adc_time0)); } else { cout << " Wrong slot/channel number(8) slot=" << SlotID << " channel =" << channel << endl;} //if (0<=pulse_number&&pulse_number<=3) m7time[pulse_number]=adc_time0; } */ //----------------------------------------------------------------------------------------------------------------------------------------- // //------------- New compressed format ---- in mode9 ------------------------------------------------------------------------------------ if(data_type == 9 ){ //--- Word_1 --- unsigned int channel = (bank[i]>>15) & 0x0F; unsigned int pedestal = (bank[i]) & 0x3FFF; //--- 0-13 bit --- unsigned int pulse_number = 0; if (m9debug>0 ) cout << "fa250::sl=" << SlotID << " chan=" << channel << " data type= " << data_type << " next flag="<< ((bank[i+1]>>31) & 1) << endl ; while(((LSWAP(bank[i+1])>>31) & 1)==0) { //-- next pulse -- pulse_number++; //--- Word_2 --- i++; uint32_t data = LSWAP(bank[i]); unsigned int pulse_sum = (data>>12) & 0x3FFFF; unsigned int nsamples_over_threshold = (data>>0 ) & 0x1FF; //--- Word_3 --- i++; data = LSWAP(bank[i]); unsigned int adc_time0 = (data>>21) & 0x1FF; unsigned int pulse_peak = (data>>3) & 0xFFF; if (m9debug>0 ) cout << " pulse=" << pulse_number << " nevt=" << nevtblk << "," << eventnr << " t=" << adc_time0 << ", peak=" << pulse_peak << ", sum=" << pulse_sum << ", ped=" << pedestal/4 << " flag="<< ((LSWAP(bank[i+1])>>31) & 1) << endl; if((0<=SlotID) && (SlotID<21) && (channel >= 0) && (channel < 16) ){ hist->Fill_F250_ped(SlotID,channel,pedestal/4); hist->Fill_F250_adc(SlotID,channel,pedestal/4); hist->Fill_F250_adc(SlotID,channel,pulse_peak); hist->f250_time->Fill(float(adc_time0)); } else { cout << " Wrong slot/channel number(9) slot=" << SlotID << " channel =" << channel << endl; } } } /* nedit $HALLD_HOME/src/libraries/DAQ/DEVIOWorkerThread.* case 8: // Pulse Time { uint32_t channel = (*iptr>>23) & 0x0F; uint32_t pulse_number = (*iptr>>21) & 0x03; uint32_t quality_factor = (*iptr>>19) & 0x03; uint32_t pulse_time = (*iptr>>0) & 0x7FFFF; if(VERBOSE>7) cout << " FADC250 Pulse Time: chan="<NEW_Df250PulseTime(rocid, slot, channel, itrigger, pulse_number, quality_factor, pulse_time); } break; case 9: // Pulse Data (firmware instroduce in Fall 2016) { // from word 1 uint32_t event_number_within_block = (*iptr>>19) & 0xFF; uint32_t channel = (*iptr>>15) & 0x0F; bool QF_pedestal = (*iptr>>14) & 0x01; uint32_t pedestal = (*iptr>>0 ) & 0x3FFF; // event_number_within_block=0 indicates error if(event_number_within_block==0){ _DBG_<<"event_number_within_block==0. This indicates a bug in firmware." << endl; exit(-1); } // Event headers may be supressed so determine event from hit data if( (event_number_within_block > current_parsed_events.size()) ) throw JException("Bad f250 event number", __FILE__, __LINE__); pe_iter = current_parsed_events.begin(); advance( pe_iter, event_number_within_block-1 ); pe = *pe_iter++; itrigger = event_number_within_block; // is this right? uint32_t pulse_number = 0; while( (*++iptr>>31) == 0 ){ if( (*iptr>>30) != 0x01) throw JException("Bad f250 Pulse Data!", __FILE__, __LINE__); // from word 2 uint32_t integral = (*iptr>>12) & 0x3FFFF; bool QF_NSA_beyond_PTW = (*iptr>>11) & 0x01; bool QF_overflow = (*iptr>>10) & 0x01; bool QF_underflow = (*iptr>>9 ) & 0x01; uint32_t nsamples_over_threshold = (*iptr>>0 ) & 0x1FF; iptr++; if( (*iptr>>30) != 0x00) throw JException("Bad f250 Pulse Data!", __FILE__, __LINE__); // from word 3 uint32_t course_time = (*iptr>>21) & 0x1FF;//< 4 ns/count uint32_t fine_time = (*iptr>>15) & 0x3F;//< 0.0625 ns/count uint32_t pulse_peak = (*iptr>>3 ) & 0xFFF; bool QF_vpeak_beyond_NSA = (*iptr>>2 ) & 0x01; bool QF_vpeak_not_found = (*iptr>>1 ) & 0x01; bool QF_bad_pedestal = (*iptr>>0 ) & 0x01; } iptr--; // backup so when outer loop advances, it points to next data defining word } break; */ //----------------------------------------------------------------------------------------------------------------------------------------- if (data_type == 10) { // Pulse Pedestal unsigned int channel = (bank[i]>>23) & 0x0F; unsigned int pulse_number = (bank[i]>>21) & 0x03; unsigned int pedestal = (bank[i]>>12) & 0x1FF; unsigned int pulse_peak = (bank[i]>>0) & 0xFFF; if (m7debug>0 ) cout << "fa250::sl=" << SlotID << " chan=" << channel << " data type= " << data_type << " pulse=" << pulse_number << " pcnt=" << m7pcnt10 << " nevt=" << nevtblk << "," << eventnr << " a="<< pulse_peak << " p=" << pedestal << " " << pulse_peak-pedestal << endl; // valid:: (rocid, slot, channel, itrigger, pulse_number, pedestal, pulse_peak) if((0<=SlotID) && (SlotID<21) && (channel >= 0) && (channel < 16) ) { //--- if (m7pcnt10<0) m7pcnt10=0; if (m7slot10<0) m7slot10=SlotID; if (m7chan10<0) m7chan10=channel; if (m7evnt10<0) m7evnt10=eventnr; if (m7slot10==SlotID && m7chan10==channel && 0<=m7pcnt10 && m7pcnt10<3 && m7evnt10==eventnr) { //-- same chan -- m7pnum10[m7pcnt10]=pulse_number; m7ampl[m7pcnt10]=pulse_peak-pedestal; if (m7debug>6) cout << "fa250:: data type= " << data_type << " same " << endl; } else { //-- next chan, fill old and reset ---- if (m7debug>0 ) cout << "fa250:: data type= " << data_type << " next " << m7slot8 << " " << SlotID << " " << m7chan10 << " " << channel << " " << m7pcnt10 << " " << m7evnt10 << " " << eventnr << endl; hist->f250_pulse->Fill(float(m7pcnt10)); m7pcnt10+=100; m7slot10=SlotID; m7chan10=channel; m7evnt10=eventnr; if (m7pcnt8>=100) { if (m7pcnt8!=m7pcnt10) { if (m7debug>0 ) cout << " Wrong pulse numbers[10] " << m7pcnt8 << " " << m7pcnt10 << endl; } else { m7pcnt8-=100; m7pcnt10-=100; int ip=0, np=-1, m7amax=-1; for (ip=0; ipm7amax) { m7amax=m7ampl[ip]; np=m7pnum10[ip]; } if (m7debug>0 ) printf(" +++> search max ampl: ip=%d ampl=%d max=%d time=%d np=%d\n",ip,m7ampl[ip],m7amax,m7time[ip],np); } if (m7amax>0) { for (ip=0; ip0 ) cout << " =====> fa250:: data type= " << data_type << " m7amax=" << m7amax << " tmax=" <(Pthr-100)) { hist->f250_time->Fill(float(adc_time)); hist->f250_pulse->Fill(float((np+1)*10)); } } } } m7pcnt8=0; m7pcnt10=0; m7evnt10=eventnr; m7pnum10[m7pcnt10]=pulse_number; m7ampl[m7pcnt10]=pulse_peak-pedestal; m7pnum8[m7pcnt8]=pulse_number; m7time[m7pcnt8]=adc_time0; m7pcnt8++; } m7pcnt10++; //--- //if ( pulse_peak>Pthr ) { hist->Fill_F250_ped(SlotID,channel,pedestal); hist->Fill_F250_adc(SlotID,channel,pulse_peak); //hist->f250_time->Fill(float(adc_time)); //} } else {cout << " Wrong slot/channel number(10) slot=" << SlotID << " channel =" << channel << endl;} } } //-- end of bank -- } //----------------------------------------------------------------------------------------- int analyzeBank_F125(unsigned int *buffer) { #define FA125_FE_CONFIG1_MODE_MASK 0x00000007 if (Debug>1) printf("F125:: mode=%d\n",hist->shmem_ptr->BOR.f125[3].fe[1].config1 & FA125_FE_CONFIG1_MODE_MASK); int F125_mode = (hist->shmem_ptr->BOR.f125[3].fe[1].config1 & FA125_FE_CONFIG1_MODE_MASK) + 1; //printf("F125_mode=%d\n",F125_mode); BankHeader Bank(buffer); if (Debug>1) Bank.print(); //int bank_size=size; int bank_size=Bank.Size-1; unsigned int *bank = (buffer+2); if (Debug>1) printf("F125:: bank ptr = %p size=%d\n",bank, bank_size); if (bank_size<=0) return 0; if (Debug>1) printf("F125:: H0=0x%08X H1=0x%08X \n",*bank,*(bank+1)); if (Debug>1) fflush(stdout); int Sz = bank_size; if (Sz<=0) return 1; int ROCSlots[21]; int OLDSLOT; int SLOTNUM, CHANNEL,WSize,DATAReady; int slotidx,idx; char Crate[128]; int C; float ped,adc1,adc2; int ltime; const int Plen=hist->f125_pulse_len; const int Pthr=200; int pulse_cnt, pulse_thr=Pthr, pulse_max1=0, pulse_max2=0, pulse_ped=0, pulse_data[Plen], pulse_sl=0, pulse_ch=0; int npk=0, ptime_data[Plen]; for (int ii=0; iiped_f125_slots[is]!=NULL) hist->ped_f125_slots[is]->Reset(); for (int k=0; k5) printf("F125:: data type =0x%x k=%d\n",((bank[k] & 0xf8000000) >>27),k); unsigned int data = bank[k]; if (((data & 0xf8000000) >>27) == 0x12) { // Event Header int SLOTvme = ((data& 0x07C00000)>>22); if (Debug>5) printf("F125:: Event Header SLOT=%d \n",SLOTvme); } if (((data & 0xf8000000) >>27) == 0x11) { // Block Trailer int SLOTvme = ((data& 0x07C00000)>>22); if (Debug>5) printf("F125:: Block Trailer SLOT=%d events=%d \n",SLOTvme, data & 0x3FFFFF); } if (((data & 0xf8000000) >>27) == 0x1d) { // Event Trailer int SLOTvme = ((data& 0x07C00000)>>22); if (Debug>5) printf("F125:: Event Trailer SLOT=%d events=%d \n",SLOTvme, data & 0x3FFFFF); } if (((data & 0xf8000000) >>27) == 0x13) { // Trigger time int SLOTvme = ((data& 0x07C00000)>>22); if (Debug>5) printf("F125:: Trigger time SLOT=%d events=%d \n",SLOTvme, data & 0x3FFFFF); } if (((data & 0xf8000000) >>27) == 0x10) { // Block Header SLOTNUM = ((data& 0x07C00000)>>22); if (Debug>5) printf("F125:: Block Header SLOT=%d \n",SLOTNUM); if (SLOTNUM!=OLDSLOT){ //cout<10){ slotidx -= 2; } MaxSlot = slotidx; } else if (((data & 0xf8000000)>>27) == 0x14) { //------- RAW data ----- if (hist->shmem_ptr->RUN_Flag==0) { //--- fill previous channel ampl -- if((0<=SLOTNUM) && (SLOTNUM<21) && ( 0<=CHANNEL) && (CHANNEL < 72)){ hist->Fill_F125(SLOTNUM,CHANNEL,pulse_max2); } } CHANNEL = ((data & 0x7F00000)>>20) ; // flash is couning channels from 1 to 72 need 0 to 71 WSize = (data & 0xFFF); DATAReady = WSize/2; if (Debug>5) printf("F125:: RAW data SLOTNUM=%d CHAN=%d DATAReady=%d\n",SLOTNUM,CHANNEL,DATAReady); /* idx = 0; ped = 0.; pedcnt = 0; ADCPedestal[ROCID][slotidx][CHANNEL] = 0.; OverThresh[ROCID][slotidx][CHANNEL] = 0; */ //------------------------------------------------------------------------- if (pulse_max2>pulse_max1 && pulse_max2<4095) { //-------------------- fill pulse shape ----- pulse_max1=pulse_max2; for (int ii=0; iif125_pulse->SetBinContent(ii+1,pulse_data[ii]); hist->f125_pulse->SetEntries(pulse_sl*100+pulse_ch); if (pulse_sl==3 ) { // WC for (int ii=0; iif125_wpulse->SetBinContent(ii+1,pulse_data[ii]); hist->f125_wpulse->SetEntries(pulse_sl*100+pulse_ch); } else { for (int ii=0; iif125_gpulse->SetBinContent(ii+1,pulse_data[ii]); hist->f125_gpulse->SetEntries(pulse_sl*100+pulse_ch); } } for (int ii=0; ii0) { // Window Raw Data values DATAReady--; if (pedcnt<20){ adc1 = (float)((data & 0x1FFF0000) >> 16); adc2 = (float)(data & 0x1FFF); if (hist->shmem_ptr->RUN_Flag!=0) { //--- calibration run, fill pedestals -- if((0<=SLOTNUM) && (SLOTNUM<21) && ( 0<=CHANNEL) && (CHANNEL < 72)){ hist->Fill_F125(SLOTNUM,CHANNEL,adc1); hist->Fill_F125(SLOTNUM,CHANNEL,adc2); } else {cout << " F125:: Wrong slot/channel number slot=" << SLOTNUM << " channel =" << CHANNEL << endl;} } /* ped += adc1; ped += adc2; ADCSamples[ROCID][slotidx][CHANNEL][idx++] = adc1; ADCSamples[ROCID][slotidx][CHANNEL][idx++] = adc2; pedcnt+=2; if (pedcnt>19){ ped /= 20.; ADCPedestal[ROCID][slotidx][CHANNEL] = ped; } */ } else { adc1 = (float)((data & 0x1FFF0000) >> 16); adc2 = (float)(data & 0x1FFF); //if (hist->shmem_ptr->RUN_Flag!=0) { //--- calibration run, fill pedestals -- if((0<=SLOTNUM) && (SLOTNUM<21) && ( 0<=CHANNEL) && (CHANNEL < 72)){ hist->Fill_F125(SLOTNUM,CHANNEL,adc1); hist->Fill_F125(SLOTNUM,CHANNEL,adc2); if (SLOTNUM==3) { // TRD hist->f125_fe55->Fill(float(adc1)); } else { // GEM hist->f125_gem->Fill(float(adc1)); } } else {cout << " F125:: Wrong slot/channel number slot=" << SLOTNUM << " channel =" << CHANNEL << endl;} //} /* ADCSamples[ROCID][slotidx][CHANNEL][idx++] = adc1; ADCSamples[ROCID][slotidx][CHANNEL][idx++] = adc2; if( (adc1-ADCPedestal[ROCID][slotidx][CHANNEL])>200. || (adc2-ADCPedestal[ROCID][slotidx][CHANNEL])>200.) { OverThresh[ROCID][slotidx][CHANNEL] = 1; } */ } pulse_sl=SLOTNUM; pulse_ch=CHANNEL; // if (strncmp(host_name,"rocfdc1",7)==0 && slot==17 && channel==31) { RFt.push_back(time_h); } if (SLOTNUM==3 || strncmp(host_name,"roctrd",6)) { // TRD if (0<=pulse_cnt && pulse_cntpulse_max2) pulse_max2=adc1; } if (adc1>pulse_thr) { hist->f125_time->Fill(float(pulse_cnt)); pulse_thr=1000000; } if (0<=pulse_cnt && pulse_cntpulse_max2) pulse_max2=adc2; } if (adc2>pulse_thr) { hist->f125_time->Fill(float(pulse_cnt)); pulse_thr=1000000; } } else { // GEM if (0<=pulse_cnt && pulse_cntpulse_max2) pulse_max2=adc1; } if (adc1>pulse_thr) { hist->f125_gtime->Fill(float(pulse_cnt)); pulse_thr=1000000; } if (0<=pulse_cnt && pulse_cntpulse_max2) pulse_max2=adc2; } if (adc2>pulse_thr) { hist->f125_gtime->Fill(float(pulse_cnt)); pulse_thr=1000000; } } if (Debug>6) printf("F125:: RAW data SLOT=%d CHAN=%d DATAReady=%d max2=%d ltime=%d pulse_cnt=%d\n" ,SLOTNUM,CHANNEL,DATAReady,pulse_max2,ltime,pulse_cnt); if (DATAReady==0) { for (int i=0; i>27) == 0x15) { //--- CDC short integr. --- CHANNEL = ((data & 0x7F00000)>>20) ; if (Debug>5) printf("F125:: CDC F125_mode=%d short integr SLOTNUM=%d CHAN=%d \n",F125_mode,SLOTNUM,CHANNEL); int letime = (data>>4) & 0x7FF ; if (F125_mode<6) hist->f125_time->Fill(float(letime)/10.); else hist->f125_stime->Fill(float(letime)/10.); int qbit=(data>>3) & 0x1 ; if (F125_mode<6) hist->f125_pulse->Fill(float(qbit+10)); k++; data = LSWAP(bank[k]); int maxampl1 = (data) & 0x1FF ; int integral = (data>>9) & 0x3FFF ; int pedestal = (data>>23) & 0xFF ; if((0<=SLOTNUM) && (SLOTNUM<21) && ( 0<=CHANNEL) && (CHANNEL < 72)){ if (F125_mode<6) hist->Fill_F125(SLOTNUM,CHANNEL,maxampl1); if (F125_mode<6) hist->f125_pulse->Fill(float(pedestal)); if (F125_mode<6) hist->F125_tdc[SLOTNUM][CHANNEL]->Fill(float(letime)/10.); } //------------------------------------------------------------------------------------------------------------------------ } else if (((data & 0xf8000000)>>27) == 0x16) { //--- FDC short integr. --- CHANNEL = ((data & 0x7F00000)>>20) ; if (Debug>5) printf("F125:: FDC short integr CHAN=%d \n",CHANNEL); int NPK = (data>>15) & 0x1F ; k++; data = LSWAP(bank[k]); //-- first only pulse -- int ptime = (data>>11) & 0xFF ; if (F125_mode<6) hist->f125_time->Fill(float(ptime)); else hist->f125_stime->Fill(float(ptime)); int pedestal = data & 0x3FF ; //------------------------------------------------------------------------------------------------------------------------ } else if (((data & 0xf8000000)>>27) == 0x19) { //--- FDC short ampl. --- CHANNEL = ((data & 0x7F00000)>>20) ; int NPK = (data>>15) & 0x1F ; if (F125_mode<6) hist->f125_pulse->Fill(float(NPK)); int letime = (data>>4) & 0x7FF ; ltime=letime/10; npk=0; ptime_data[npk]=ltime; npk++; int qbit=(data>>3) & 0x1 ; if (F125_mode<6) hist->f125_pulse->Fill(float(qbit+10)); if (Debug>5) printf("F125:: FDC short ampl F125_mode=%d CHAN=%d NPK=%d letime=%d\n",F125_mode,CHANNEL,NPK,letime/10); if (F125_mode<6) hist->f125_time->Fill(float(letime)/10.); else hist->f125_stime->Fill(float(letime)/10.); if (strncmp(host_name,"roctrd",6)==0) { if (F125_mode<6) { if (SLOTNUM==3 || strncmp(host_name,"roctrd",6)) { // TRD hist->f125_time->Fill(float(letime)/10.); hist->f125_wpulse->Fill(float(NPK)); } else { hist->f125_gtime->Fill(float(letime)/10.); hist->f125_gpulse->Fill(float(NPK)); } } } for (int i=0; i>11) & 0xFF ; //-- labuda -- ptime_data[npk]=ptime; npk++; //printf("ptime=%d\n",ptime); int pedestal = data & 0x7FF ; int ampl1 = (data>>19) & 0xFFF ; if (F125_mode<6) hist->f125_stime->Fill(float(ptime)); if((0<=SLOTNUM) && (SLOTNUM<21) && ( 0<=CHANNEL) && (CHANNEL < 72)) { if (F125_mode<6) { hist->f125_pulse->Fill(float(pedestal)); hist->Fill_F125(SLOTNUM,CHANNEL,ampl1); } if (F125_mode<6) hist->F125_tdc[SLOTNUM][CHANNEL]->Fill(float(letime)/10.); if (strncmp(host_name,"roctrd",6)==0) { if (F125_mode<6) { hist->Fill_F125(SLOTNUM,CHANNEL,ampl1); if (SLOTNUM==3 || strncmp(host_name,"roctrd",6)) { // TRD hist->f125_fe55->Fill(float(ampl1)); hist->f125_time->Fill(float(ptime)); } else { hist->f125_gem->Fill(float(ampl1)); hist->f125_gtime->Fill(float(ptime)); } } } } //if (F125_mode<6) hist->f125_fe55->Fill(float(ampl1)); } } } //-- end of block } //--- end analyse f125 --- //----------------------------------------------------------------------------------------- // FILL CAEN TDC //----------------------------------------------------------------------------------------- void Hist::Fill_CAEN(int slot, int chan,unsigned int tdc) { if (!CTDC[slot][chan]) { sprintf(hist_name,"%s:Caen_TDC:%02d:%02d",host_name,slot,chan); printf("Book hist: %s \n",hist_name); CTDC[slot][chan] = new TH1D(hist_name,hist_name, 500, 0., 32780.0); ALL_1D_HIST->Add(CTDC[slot][chan]); // if (!tdc_occup2D_ctdc) { sprintf(hist_name,"%s:CTDC_occ2D",host_name); printf("Book hist: %s \n",hist_name); tdc_occup2D_ctdc = new TH2D(hist_name,hist_name,MAXSLOT_CAEN,0.5,MAXSLOT_CAEN+0.5, MAXCHAN_CAEN,-0.5,MAXCHAN_CAEN-0.5); tdc_occup2D_ctdc->GetXaxis()->SetTitle("Slot Number"); tdc_occup2D_ctdc->GetYaxis()->SetTitle("Channel"); ALL_2D_HIST->Add(tdc_occup2D_ctdc); } } //printf("Fill::: Slot=%02d CTDC=%02d ptr=%p \n",slot,chan,CTDC[slot][chan]); CTDC[slot][chan]->Fill((double)tdc); tdc_prof_caen->Fill(float(slot*MAXCHAN_CAEN+chan),float(tdc)); tdc_occup2D_ctdc->Fill(float(slot),float(chan),1.); } //----------------------------------------------------------------------------------------- // FILL F1TDC //----------------------------------------------------------------------------------------- void Hist::Fill_F1TDC(int slot, int chan, int time) { if (!F1TDC[slot][chan]) { sprintf(hist_name,"%s:F1TDC:%02d:%02d",host_name,slot,chan); printf("Book hist: %s \n",hist_name); F1TDC[slot][chan] = new TH1D(hist_name,hist_name, 1000, -0.5, 69999.5); F1TDC[slot][chan]->GetYaxis()->SetTitle("Events"); F1TDC[slot][chan]->GetXaxis()->SetTitle("Time"); ALL_1D_HIST->Add(F1TDC[slot][chan]); // if (!tdc_occup2D_f1tdc) { sprintf(hist_name,"%s:F1TDC_occ2D",host_name); printf("Book hist: %s \n",hist_name); tdc_occup2D_f1tdc = new TH2D(hist_name,hist_name,MAXSLOT_F1TDC,0.5,MAXSLOT_F1TDC+0.5, MAXCHAN_F1TDC,-0.5,MAXCHAN_F1TDC-0.5); tdc_occup2D_f1tdc->GetXaxis()->SetTitle("Slot Number"); tdc_occup2D_f1tdc->GetYaxis()->SetTitle("Channel"); ALL_2D_HIST->Add(tdc_occup2D_f1tdc); } } //printf("Fill::: Slot=%02d F250=%02d ptr=%p \n",slot,chan,F1TDC[slot][chan]); F1TDC[slot][chan]->Fill((double)time); tdc_prof_f1tdc->Fill(float(slot*MAXCHAN_F1TDC+chan),float(time)); tdc_occup_f1tdc->Fill(float(slot*MAXCHAN_F1TDC+chan),1.); tdc_occup2D_f1tdc->Fill(float(slot),float(chan),1.); } //----------------------------------------------------------------------------------------- // FILL ADC 125 //----------------------------------------------------------------------------------------- void Hist::Fill_F125(int slot, int chan, int adc) { if (!F125_adc[slot][chan]) { sprintf(hist_name,"%s:F125_adc:%02d:%02d",host_name,slot,chan); printf("Book hist: %s \n",hist_name); F125_adc[slot][chan] = new TH1D(hist_name,hist_name, 5000, -0.5, 4999.5); ALL_1D_HIST->Add(F125_adc[slot][chan]); sprintf(hist_name,"%s:F125_tdc:%02d:%02d",host_name,slot,chan); printf("Book hist: %s \n",hist_name); F125_tdc[slot][chan] = new TH1D(hist_name,hist_name,220, -0.5,219.5); ALL_1D_HIST->Add(F125_tdc[slot][chan]); if (!ped_f125_slots[slot]) { sprintf(hist_name,"%s:F125_2D:%02d",host_name,slot); printf("Book hist: %s \n",hist_name); ped_f125_slots[slot] = new TH2D(hist_name,hist_name,MAXCHAN_f125,0.5,MAXCHAN_f125+0.5, 500 ,-0.5, 4100-0.5); ped_f125_slots[slot]->GetXaxis()->SetTitle("Chan"); ped_f125_slots[slot]->GetYaxis()->SetTitle("ADC value"); ALL_2D_HIST->Add(ped_f125_slots[slot]); } } //printf("Fill::: Slot=%02d F125=%02d ptr=%p \n",slot,chan,F125_adc[slot][chan]); F125_adc[slot][chan]->Fill((double)adc); ped_f125_prof->Fill(float(slot*MAXCHAN_f125+chan),float(adc)); ped_f125_slots[slot]->Fill(float(chan+1),float(adc)); } //----------------------------------------------------------------------------------------- // FILL ADC //----------------------------------------------------------------------------------------- void Hist::Fill_F250_adc(int slot, int chan, int adc) { if (!F250_adc[slot][chan]) { sprintf(hist_name,"%s:F250_adc:%02d:%02d",host_name,slot,chan); printf("Book hist: %s \n",hist_name); int f250mx=4090; F250_adc[slot][chan] = new TH1D(hist_name,hist_name, f250mx, -0.5,f250mx-0.5); F250_adc[slot][chan]->GetYaxis()->SetTitle("Events"); F250_adc[slot][chan]->GetXaxis()->SetTitle("ADC"); ALL_1D_HIST->Add(F250_adc[slot][chan]); // sprintf(hist_name,"%s:F250_adc_all:%02d:%02d",host_name,slot,chan); printf("Book hist: %s \n",hist_name); F250_adc_all[slot][chan] = new TH1D(hist_name,hist_name, 1000, -1000, 9000.); F250_adc_all[slot][chan]->GetYaxis()->SetTitle("Events"); F250_adc_all[slot][chan]->GetXaxis()->SetTitle("ADC"); ALL_RUN_HIST->Add(F250_adc_all[slot][chan]); // if (!adc_f250_slots[slot]) { sprintf(hist_name,"%s:F250_2Dadc:%02d",host_name,slot); printf("Book hist: %s \n",hist_name); adc_f250_slots[slot] = new TH2D(hist_name,hist_name,MAXCHAN,0.5,MAXCHAN+0.5, 50 ,0.5,4096); adc_f250_slots[slot]->GetXaxis()->SetTitle("Chan"); adc_f250_slots[slot]->GetYaxis()->SetTitle("ADC value"); ALL_2D_HIST->Add(adc_f250_slots[slot]); } } //printf("Fill::: Slot=%02d F250=%02d ptr=%p adc=%d\n",slot,chan,F250_adc[slot][chan],adc); F250_adc[slot][chan]->Fill((double)adc); F250_adc_all[slot][chan]->Fill((double)adc); adc_f250_prof->Fill(float(slot*MAXCHAN+chan),float(adc)); if (adc < 1 || adc > 4095 ) { //printf("******>>>> ERROR data Slot=%d Chan=%d val=%d: \n",slot,chan,adc); if (adc>4095) adc=4096; if (adc<1) adc=0; } adc_f250_slots[slot]->Fill(float(chan+1),float(adc)); } //----------------------------------------------------------------------------------------- // FILL PED //----------------------------------------------------------------------------------------- void Hist::Fill_F250_ped(int slot, int chan, int ped) { if (!F250_ped[slot][chan]) { sprintf(hist_name,"%s:F250_ped:%02d:%02d",host_name,slot,chan); printf("Book hist: %s \n",hist_name); F250_ped[slot][chan] = new TH1D(hist_name,hist_name, 150, -0.5, 149.5); F250_ped[slot][chan]->GetYaxis()->SetTitle("Events"); F250_ped[slot][chan]->GetXaxis()->SetTitle("ped"); ALL_1D_HIST->Add(F250_ped[slot][chan]); } //printf("Fill::: Slot=%02d F250=%02d ptr=%p \n",slot,chan,F250_ped[slot][chan]); F250_ped[slot][chan]->Fill((double)ped); ped_f250_prof->Fill(float(slot*MAXCHAN+chan),float(ped)); //ped_f250_slots[slot]->Fill(float(chan+1),float(ped)); } //----------------------------------------------------------------------------------------- // FILL F250 Scalers //----------------------------------------------------------------------------------------- void Hist::Fill_F250_Scalers(int slot, int chan, double rate) { if (!F250scalers) { sprintf(hist_name,"%s:F250_Scalers",host_name); printf("Book hist: %s \n",hist_name); F250scalers = new TH2F(hist_name,hist_name,MAXSLOT,0.5,MAXSLOT+0.5, MAXCHAN,-0.5,MAXCHAN-0.5); F250scalers->GetXaxis()->SetTitle("Slot Number"); F250scalers->GetYaxis()->SetTitle("Channel"); ALL_2D_HIST->Add(F250scalers); } //if (chan==15) printf("Fiiiiiiiiiiiiiiiiil slot=%d chan=%d rate=%d !!!\n",slot,chan,rate); F250scalers->SetBinContent(slot,chan+1,rate); F250scalers->SetEntries(1.); } //----------------------------------------------------------------------------------------- // FIT FADC pedestals monitor //----------------------------------------------------------------------------------------- int Hist::Fit_PedMon(void) { printf("Fit_PedMon()\n"); TH1 *h1=NULL; int fit_min_stat=100; f250_pedmean->Reset(""); f250_pedsigma->Reset(""); ped_f250_prof->Reset(""); for (int is=0; is=max_dac) bin=max_dac-1; if (bin<0) bin=0; int noent=0; if (h1) noent=h1->GetEntries(); double integr=0; if (h1) integr=h1->Integral(""); //if ((noent/4)>integr) continue; if (integr>fit_min_stat) { //-- OK for fit --- double min, max,binmax,h_rms,h_mean; binmax=h1->GetBinLowEdge(h1->GetMaximumBin()); h_rms=h1->GetRMS(1); h_mean=h1->GetMean(1); //min=binmax-6*h_rms ; //-- 6 RMS fit //max=binmax+6*h_rms ; //-- 6 RMS fit min=binmax-3 ; //-- +-6 bin fit max=binmax+3 ; //-- +-6 bin fit printf("Pedestal Mon Fit:: init: chan=%d, slot=%d, bin=%d, noent=%d, integr=%f, min=%f, max=%f, binmax=%f, h_rms=%f, h_mean=%f\n" ,chan,slot,bin,noent,integr,min,max,binmax,h_rms,h_mean); TF1 *fit1 = new TF1("fit1","gaus",min,max); h1->Fit("fit1","RQN"); //--- PED FITTING is here !!! float mean=fit1->GetParameter(1); float sigma=fit1->GetParameter(2); delete fit1; printf("Pedestal Mon Fit:: mean=%f sigma=%f\n",mean,sigma); pedmon[bin].mean=mean; pedmon[bin].sigma=sigma; pedmon[bin].noent=noent; pedmon[bin].updated=time(NULL); pedmon[bin].status=1; // OK h1->Reset(""); if (shmem_ptr) { shmem_ptr->pedmon[bin].mean=mean; shmem_ptr->pedmon[bin].sigma=sigma; shmem_ptr->pedmon[bin].noent=noent; shmem_ptr->pedmon[bin].updated=time(NULL); shmem_ptr->pedmon[bin].status=1; // OK } } //---------------- if (pedmon[bin].status>0) { f250_pedmean->Fill(pedmon[bin].mean); f250_pedsigma->Fill(pedmon[bin].sigma); } } } //--- end ped hist loop } //----------------------------------------------------------------------------------------- // FIT all FADC pedestals //----------------------------------------------------------------------------------------- int Hist::Fit_Hist(int RUN_NUM, int DAC, int FADC, int* new_dac, int *new_thr, int max_dac) { printf("Fit_Hist(%d,%d) FADC type=%d \n", RUN_NUM, DAC, FADC); FILE *DacFile=NULL; char DacName[256]; TObject *obj; TH1 *h1; int slot, chan, Nf250=0, Nf125=0; TIter next1(ALL_1D_HIST); TH1D *fit_m; TH1D *fit_s; FADC_DAC[Nfits]=DAC; int CAL_min_stat=100; float CAL_target_PED=100.; sprintf(DacName, "%s/ROOT_HIST/DAC_%s_%d_Run_%d.txt",getenv("HOME"),host_name,DAC,RUN_NUM); printf("Open file :%s: \n",DacName); if((DacFile=fopen(DacName,"w")) == NULL) { printf("Can not open file %s \n",DacName); } else { fprintf(DacFile," Slot Channel DAC THR bin \n"); } //sleep(5); while ((obj = next1())) { if (Debug>1) obj->Print(); h1=(TH1 *) obj; slot=-1, chan=-1; //----------- parsing hist name ------------------------- string s = h1->GetName(); int param=0; string host_name; string hist_name; string slot_name; string chan_name; vector params = Parsing(s,":"); if (params.size()==4) { for (int ii=0; ii1) std::cout << "nparam =" << ii << " name=:" << params[ii] << ":"<MAXSLOT || chan<0 || chan>MAXCHAN_f125 ) continue; Nf125++; } if (FADC==1 && hist_name=="F250_adc") { slot=str2int(slot_name,10); chan=str2int(chan_name,10); printf(" Fit:: F250 Slot=%d Chan=%d\n",slot,chan); if ( slot<0 || slot>MAXSLOT || chan<0 || chan>MAXCHAN ) continue; Nf250++; } if (slot<0) continue; } else { continue; } //--------------------------------------------------------------------------------------------------------------- int noent=h1->GetEntries(); double integr=h1->Integral(""); if ((noent/4)>integr) if(DacFile) fprintf(DacFile,"Statics error: slot=%02d chan=%02d : noent=%d integr=%f Nfits=%d\n",slot,chan,noent,integr,Nfits); if (integr>CAL_min_stat) { double min, max,binmax,h_rms; binmax=h1->GetBinLowEdge(h1->GetMaximumBin()); h_rms=h1->GetRMS(); double sr=3.; if (FADC==0) sr=10.; min=binmax-sr*h_rms ; //-- 6 RMS fit max=binmax+sr*h_rms ; //-- 6 RMS fit //min=binmax-6 ; //-- -6 bin fit //max=binmax+6 ; //-- +6 bin fit TF1 *fit1 = new TF1("fit1","gaus",min,max); //h1->Fit("fit1","RQN"); //--- ADC FITTING is here !!! h1->Fit("fit1","RQ0"); //--- ADC FITTING is here !!! float mean=fit1->GetParameter(1); float sigma=fit1->GetParameter(2); /* h1->Fit("gaus","0"); TF1 *ga = h1->GetFunction("gaus"); //ga->SetLineColor(2); ga->SetLineWidth(1) ; float mean=ga->GetParameter(1); float sigma=ga->GetParameter(2); */ delete fit1; printf("Pedestal Fit:%d: mean=%f sigma=%f Debug=%d slot=%d chan=%d \n",Nfits,mean,sigma,Debug,slot,chan); int bin; if (FADC==0) bin = slot*MAXCHAN_f125+chan; if (FADC==1) bin = slot*MAXCHAN+chan; if (bin>=max_dac) bin=max_dac-1; if (bin<0) bin=0; FADC_mean[Nfits][bin]=mean; FADC_sigma[Nfits][bin]=sigma; //=============================== DEBUG PLOT FIT ======================================= if (Debug>0 && slot==Debug_Slot && chan==Debug_Chan ) { //-- PLOT --- char ctitle[100]; sprintf(ctitle,"Fit:: host=%s SLOT=%d CHAN=%d ",host_name.c_str(),slot,chan); printf("Plot Fit:%d: host=%s SLOT=%d CHAN=%d \n",Nfits,host_name.c_str(),slot,chan); canvas1->SetTitle(ctitle); //TH2F *frame = new TH2F("frame","",ncx,xmin,xmax,ncy,ymin,ymax); //TLine *line1 = new TLine(0.05,0.05,0.95,0.95); canvas1->cd(Nfits+1); /* TAxis *axis1 = h1->GetXaxis(); Int_t binmin = axis1->GetFirst(); Int_t binmax = axis1->GetLast(); h1->GetXaxis()->SetRange(min,max); */ fit1->DrawCopy(); h1->DrawCopy("sames"); //h1->GetXaxis()->SetRange(binmin,binmax); //sprintf(ctitle,"Fit:: %f ",mean); //TPaveLabel *hello = new TPaveLabel(0.2,0.4,0.8,0.6,ctitle); //hello->Draw(); canvas1->Modified();canvas1->Update(); printf("Done:: SLOT=%d CHAN=%d \n",slot,chan); //if (Nfits==3) theApp->Run(); } //----------------------------------------------------------------------------------------- if (Nfits==0) { //--- fit first point if (0= d0 || d0>60000 ) d0=d1; } else { if(DacFile) fprintf(DacFile,"Error: slot=%02d chan=%02d : noent=%d integr=%f Nfits=%d\n",slot,chan,noent,integr,Nfits); } new_dac[bin]=floor(d0+0.5); //new_thr[bin]=floor(sigma*(5+5*FADC)+0.5); //-- 5/10 sigma THR -- new_thr[bin]=floor(sigma*nSigmas+0.5); //-- 5 sigma THR -- printf("Fit:%d: dac=%d m0=%f,d0=%f,m1=%f,d1=%f,m2=%f,d2=%f\n",Nfits,new_dac[bin],m0,d0,m1,d1,m2,d2); if(DacFile) fprintf(DacFile,"%3d %7d %7d %3d %3d : m0=%f, d0=%f, m1=%f, d1=%f, m2=%f, d2=%f\n" ,slot,chan,new_dac[bin],new_thr[bin],bin,m0,d0,m1,d1,m2,d2); printf("ped_f125_fit_s[0]=%p\n",ped_f125_fit_s[0]); if (FADC==0) ped_f125_fit_s[0]->SetBinContent(bin+1,double(new_thr[bin])); if (FADC==1) ped_f250_fit_s[0]->SetBinContent(bin+1,double(new_thr[bin])); } //----------------------------------------------------------------------------------------- if (Nfits==2 && new_dac[bin]>1) { //--- Calculate real PED and THR --- //new_thr[bin]=floor((mean+sigma*(5+5*FADC))+0.5); //-- 5/10 sigma THR -- //new_thr[bin]=floor((mean+sigma*5)+0.5); //-- 5 sigma THR -- new_thr[bin]=floor(sigma*nSigmas+0.5); //-- 5 sigma THR -- if (FADC==0) new_thr[bin]=std::max(new_thr[bin],33); // min thr. for 125 is 33 printf("New THR:: bin=%d (sl=%d,ch=%d) mean=%f sigma=%f, THR=%d\n",bin,slot,chan,mean,sigma,new_thr[bin]); //---- DAC correction --- float m0=CAL_target_PED; //-> +20 ? float m1=FADC_mean[2][bin]; float m2=FADC_mean[1][bin]; float d1=new_dac[bin]; float d2=FADC_DAC[1]; float aa=1; float bb=0; float d0=d1; if (m1!=m2) { aa=(d2-d1)/(m2-m1); bb=d1-aa*m1; d0=aa*m0+bb; if ( 0 >= d0 || d0>60000 ) d0=d1; } else { if(DacFile) fprintf(DacFile,"Error2: slot=%02d chan=%02d : noent=%d integr=%f Nfits=%d\n",slot,chan,noent,integr,Nfits); } if(DacFile) fprintf(DacFile,"%3d %7d %7d %3d %3d : m0=%f, d0=%f, m1=%f, d1=%f, m2=%f, d2=%f\n" ,slot,chan,new_dac[bin],new_thr[bin],bin,m0,d0,m1,d1,m2,d2); new_dac[bin]=floor(d0+0.5); //------------------------ if(DacFile) fprintf(DacFile,"New THR:: bin=%d mean=%f sigma=%f, THR=%d Corr.DAC=%d \n",bin,mean,sigma,new_thr[bin],new_dac[bin]); if (FADC==0) ped_f125_fit_s[0]->SetBinContent(bin+1,double(new_thr[bin])); if (FADC==1) ped_f250_fit_s[0]->SetBinContent(bin+1,double(new_thr[bin])); if (FADC==0) ped_f125_fit_m[1]->SetBinContent(bin+1,mean); if (FADC==1) ped_f250_fit_m[1]->SetBinContent(bin+1,mean); if (FADC==0) ped_f125_fit_s[1]->SetBinContent(bin+1,sigma); if (FADC==1) ped_f250_fit_s[1]->SetBinContent(bin+1,sigma); printf("Fit:%d: corr dac=%d m0=%f,d0=%f,m1=%f,d1=%f,m2=%f,d2=%f\n",Nfits,new_dac[bin],m0,d0,m1,d1,m2,d2); //=============================== DEBUG PLOT LINE ======================================= if (Debug>0 && slot==Debug_Slot && chan==Debug_Chan ) { //-- PLOT --- canvas1->cd(Nfits+3); gPad->SetGrid(); printf("Draw line Fit:%d: mean=%f sigma=%f\n",Nfits,mean,sigma); int bin; if (FADC==0) bin = slot*MAXCHAN_f125+chan; if (FADC==1) bin = slot*MAXCHAN+chan; if (bin>=max_dac) bin=max_dac-1; if (bin<0) bin=0; char ctitle[100]; printf("Plot Line Fit:%d: host=%s SLOT=%d CHAN=%d \n",Nfits,host_name.c_str(),slot,chan); sprintf(ctitle,"Fit:: %f ",mean); double xmax2=4100; if (FADC==0) xmax2=51000; TH2F *frame = new TH2F("frame",ctitle,100,0.,xmax2,100,0.,xmax2); frame->Draw(); //TPaveLabel *hello = new TPaveLabel(0.2,0.4,0.8,0.6,ctitle); //hello->Draw(); TLine *line100 = new TLine(0.,100.,xmax2-100.,100.); line100->SetLineColor(2); line100->Draw(); float f0=FADC_mean[0][bin]; float f1=FADC_mean[1][bin]; float f2=FADC_mean[2][bin]; float x0=3000; float x1=FADC_DAC[1]; float x2=d1; /*new_dac[bin];*/ float x3=d0; TLine *line1 = new TLine(x0,f0,x1,f1); line1->SetLineColor(4); line1->Draw(); TLine *line2 = new TLine(x1,f1,x2,f2); line2->SetLineColor(4); line2->Draw(); TLine *line3 = new TLine(x2,f2,d0,m0); line3->SetLineColor(1); line3->Draw(); TMarker *p0 = new TMarker(x0, f0, 20); p0->Draw(); //-- O TMarker *p1 = new TMarker(x1, f1, 21); p1->Draw(); //-- [] TMarker *p2 = new TMarker(x2, f2, 22); p2->Draw(); //-- ^ TMarker *p3 = new TMarker(d0, m0, 23); p3->Draw(); //-- v canvas1->cd(Nfits+4); gPad->SetGrid(); sprintf(ctitle,"Zoom:: load dac=%f ",new_dac[bin]); TH2F *frame1 = new TH2F("frame1",ctitle,100,d0-50,d0+50,100,m0-30,m0+30); frame1->Draw(); line100->Draw(); line1->Draw();line2->Draw();line3->Draw(); p0->Draw();p1->Draw(); p2->Draw();p3->Draw(); printf("Plot:%d: m0=%f,d0=%f,x0=%f,f0=%f,x1=%f,f1=%f,x2=%f,f2=%f\n",Nfits,m0,d0,x0,f0,x1,f1,x2,f2); canvas1->Modified();canvas1->Update(); printf("Line Done:: SLOT=%d CHAN=%d \n",slot,chan); } } //----------------------------------------------------------------------------------------- if (Nfits>2) { //--- Calculate real PED and THR --- printf("FIT:%d: bin=%d (sl=%d,ch=%d) mean=%f sigma=%f, THR=%d\n",Nfits,bin,slot,chan,mean,sigma); } //----------------------------------------------------------------------------------------- int Nbins=0; if (FADC==0) { fit_m=ped_f125_fit_m[Nfits]; fit_s=ped_f125_fit_s[Nfits]; Nbins=MAXBIN_f125;} if (FADC==1) { fit_m=ped_f250_fit_m[Nfits]; fit_s=ped_f250_fit_s[Nfits]; Nbins=MAXBIN; } if (fit_m==NULL) { //--- Fill fit results --- char hist_name[256]; if (FADC==0) sprintf(hist_name,"%s:F125_Fit_m:%d",host_name.c_str(),Nfits); if (FADC==1) sprintf(hist_name,"%s:F250_Fit_m:%d",host_name.c_str(),Nfits); printf("Book hist: %s \n",hist_name); fit_m = new TH1D(hist_name,hist_name,Nbins,-0.5,Nbins-0.5); fit_m->SetMarkerStyle(20); fit_m->SetMarkerSize(0.3); fit_m->SetMarkerColor(Nfits*2+2); ALL_FIT_HIST->Add( fit_m ); if (FADC==0) sprintf(hist_name,"%s:F125_Fit_s:%d",host_name.c_str(),Nfits); if (FADC==1) sprintf(hist_name,"%s:F250_Fit_s:%d",host_name.c_str(),Nfits); printf("Book hist: %s \n",hist_name); //sleep(5); fit_s = new TH1D(hist_name,hist_name,Nbins,-0.5,Nbins-0.5); fit_s->SetMarkerStyle(20); fit_s->SetMarkerSize(0.3); fit_s->SetMarkerColor(Nfits*2+2); ALL_FIT_HIST->Add( fit_s ); } fit_m->Fill(float(bin),mean); fit_s->Fill(float(bin),sigma); if (FADC==0) { ped_f125_fit_m[Nfits]=fit_m; ped_f125_fit_s[Nfits]=fit_s; } if (FADC==1) { ped_f250_fit_m[Nfits]=fit_m; ped_f250_fit_s[Nfits]=fit_s; } } } //-- hist loop -- if (DacFile) fclose(DacFile); DacFile=NULL; int this_Nfits = Nfits; if (Nfits<(MAX_FIT-1)) Nfits++; return this_Nfits; } //--------------------------------------------------------------------------------------- void Hist::FillPed(int bin,double ped,int FADC) { if (FADC==0 && ped_f125_fit_m[1]!=NULL ) ped_f125_fit_m[1]->SetBinContent(bin+1,ped); if (FADC==1 && ped_f250_fit_m[1]!=NULL ) ped_f250_fit_m[1]->SetBinContent(bin+1,ped); } void Hist::FillSigma(int bin,double sigma,int FADC) { if (FADC==0 && ped_f125_fit_s[1]!=NULL ) ped_f125_fit_s[1]->SetBinContent(bin+1,sigma); if (FADC==1 && ped_f250_fit_s[1]!=NULL ) ped_f250_fit_s[1]->SetBinContent(bin+1,sigma); } //----------------------------------------------------------------------------------------- // FILL DISCR Scalers //----------------------------------------------------------------------------------------- void Hist::Fill_DISCR_Scalers(int slot, int chan, double rate) { if (!DISCRscalers) { sprintf(hist_name,"%s:DISCR_Scalers",host_name); printf("Book hist: %s \n",hist_name); DISCRscalers = new TH2F(hist_name,hist_name,MAXSLOT,0.5,MAXSLOT+0.5, MAXCHAN,-0.5,MAXCHAN-0.5); DISCRscalers->GetXaxis()->SetTitle("Slot Number"); DISCRscalers->GetYaxis()->SetTitle("Channel"); ALL_2D_HIST->Add(DISCRscalers); } //if (chan==15) printf("Fiiiiiiiiiiiiiiiiil slot=%d chan=%d rate=%d !!!\n",slot,chan,rate); DISCRscalers->SetBinContent(slot,chan+1,rate); DISCRscalers->SetEntries(1); DscRate[slot][chan]=rate; } //----------------------------------------------------------------------------------------- // FILL DIRC Scalers //----------------------------------------------------------------------------------------- void Hist::Fill_DIRC_Scalers(int slot, int fiber, int chan, double rate) { if (!DIRCscalers) { sprintf(hist_name,"%s:DIRC_Scalers",host_name); printf("Book hist: %s \n",hist_name); int MAXDY = DIRC_USED_SLOT*DIRC_MAX_FIBER; //-- 3 slot x 24 fibers int MAXDX = DIRC_MAX_SCALER_FIBER; // -- 192 :: 1 fiber data DIRCscalers = new TH2F(hist_name,hist_name,MAXDX,0.5,MAXDX+0.5, MAXDY,-0.5,MAXDY-0.5); DIRCscalers->GetXaxis()->SetTitle("PMT channel"); DIRCscalers->GetYaxis()->SetTitle("slot/fiber"); ALL_2D_HIST->Add(DIRCscalers); } //if (chan==15) printf("Fiiiiiiiiiiiiiiiiil slot=%d chan=%d rate=%d !!!\n",slot,chan,rate); //printf("Fill_DIRC_Scalers:: X=%d Y=%d rate =%f \n",chan%DIRC_MAX_FIBER+1,slot+chan/DIRC_MAX_FIBER,rate); DIRCscalers->SetBinContent(chan+1, slot*DIRC_MAX_FIBER+fiber+1,rate); DIRCscalers->SetEntries(1); //DscRate[slot][chan]=rate; } //------------------------------------------ void Hist::Reset_DIRC_Scalers(int slot) { if (DIRCscalers) { //DIRCscalers->Reset(" "); for (int ic=0; icSetBinContent(ic+1, slot*DIRC_MAX_FIBER+jf+1, 0.); } } //----------------------------------------------------------------------------------------- // FILL DIRC Data //----------------------------------------------------------------------------------------- void Hist::Fill_DIRC_Data(int slot, int fiber, int chan, double data) { const Int_t nx = DIRC_MAX_DATA_FIBER; //-- 9 : single fiber data const Int_t ny = DIRC_USED_SLOT*DIRC_MAX_FIBER; //-- 3 slots * 24 fibers const char *cdata[DIRC_MAX_DATA_FIBER] = {"T.fpga", "T.reg0", "T.reg1", "pcb_5v", "pcb_3.3v", "vccint_1v", "vccaux_1.8v", "mgt_1v", "mgt_1.2v"}; if (!DIRCdata) { sprintf(hist_name,"%s:DIRC_Data",host_name); printf("Book hist: %s \n",hist_name); #if 0 DIRCdata = new TH2F(hist_name,hist_name,nx,0.5,nx+0.5, ny,-0.5,ny-0.5); #else DIRCdata = new TH2F(hist_name,hist_name,3,0,3,ny,-0.5,ny-0.5); #if ROOT_VERSION_CODE > ROOT_VERSION(6,0,0) DIRCdata->SetCanExtend(TH1::kXaxis); #else DIRCdata->SetBit(TH1::kCanRebin); #endif DIRCdata->SetStats(0); for (Int_t ix=0;ixRndm()*2.); //printf("%d %d rx=%f %s \n",ix,iy,rx,cdata[ix]); //DIRCdata->Fill(crates[iy],cdata[ix],rx); DIRCdata->Fill(cdata[ix],iy,0.); } } printf(" initialized \n"); DIRCdata->SetMarkerSize(0.6); //-- text size DIRCdata->SetMarkerColor(2); //-- text color DIRCdata->LabelsDeflate("X"); DIRCdata->LabelsDeflate("Y"); DIRCdata->LabelsOption("d"); DIRCdata->GetXaxis()->SetLabelSize(0.03); DIRCdata->GetYaxis()->SetLabelSize(0.02); #endif //DIRCdata->GetXaxis()->SetTitle("data"); DIRCdata->GetYaxis()->SetTitle("slot/fiber"); ALL_2D_HIST->Add(DIRCdata); } if (Debug>3) printf("DIRCdata Fill:: %d %d %f \n",chan+1, slot*DIRC_MAX_FIBER+fiber+1, data); DIRCdata->SetBinContent(chan+1, slot*DIRC_MAX_FIBER+fiber+1, data); DIRCdata->SetEntries(1); } //---------------------------------------- void Hist::Reset_DIRC_Data(int slot) { if (DIRCdata) { //DIRCdata->Reset(" "); for (int ic=0; icSetBinContent(ic+1, slot*DIRC_MAX_FIBER+jf+1, 0.); } } //----------------------------------------------------------------------------------------- // BOOK HIST //----------------------------------------------------------------------------------------- Hist::Hist () { printf("------------------------ Constructor Hist !!! ---------------------------\n"); gethostname(host_name, 80); //rootspy = new DRootSpy(); // Define some histograms to file main = gDirectory; gDirectory->mkdir("ROCS")->cd(); gDirectory->pwd(); TH1::AddDirectory(kFALSE); shmem_ptr=NULL; //--- reset shared memory pointer // Random number generator rndm = new TRandom(); ALL_1D_HIST=new TList(); ALL_2D_HIST=new TList(); ALL_FIT_HIST=new TList(); ALL_Prof_HIST=new TList(); ALL_NT_HIST=new TList(); ALL_RUN_HIST=new TList(); // signal(SIGINT, sigHandler); DONE = false; ROOT_WRITE_LOCK = 1; Nslots=0; pDscRate=&DscRate[0][0]; root_file= NULL; theApp=NULL; if (Debug>0 && Debug_Slot>0) { theApp = new TApplication("App", NULL, 0); char titfit[128]; sprintf(titfit,"Fit Ped slot=%d chan=%d",Debug_Slot,Debug_Chan); canvas1 = new TCanvas("canvas1",titfit,1000,800); gStyle->SetOptFit(11111); gStyle->SetOptStat(11111); canvas1->Divide(3,2); canvas1->Modified();canvas1->Update(); printf("open canvas \n"); } //--- DAQ --- sprintf(hist_name,"%s:EventSize",host_name); printf("Book hist: %s \n",hist_name); EventSize = new TH1D(hist_name,hist_name, 200, -0.5, 400.); //-- kByte ALL_1D_HIST->Add(EventSize); sprintf(hist_name,"%s:RunInfo",host_name); printf("Book hist: %s \n",hist_name); RunInfo = new TH1I(hist_name,hist_name, 100, -0.5, 99.5); ALL_1D_HIST->Add(RunInfo); sprintf(hist_name,"%s:size2time",host_name); printf("Book hist: %s \n",hist_name); size2time = new TH2D(hist_name,hist_name,100,0.,200,100,0.,2000); size2time->GetXaxis()->SetTitle("event size, kB"); size2time->GetYaxis()->SetTitle("readout time, us "); ALL_2D_HIST->Add(size2time); //-- ROL_1 hist sprintf(hist_name,"%s:rol_1_1_tiprimary",host_name); printf("Book hist: %s \n",hist_name); rol_1[1] = new TH1D(hist_name,hist_name, 500, -0.5, 499.5 ); ALL_1D_HIST->Add(rol_1[1]); sprintf(hist_name,"%s:rol_1_2_vmelist",host_name); printf("Book hist: %s \n",hist_name); rol_1[2] = new TH1D(hist_name,hist_name, 500, -0.5, 499.5); ALL_1D_HIST->Add(rol_1[2]); sprintf(hist_name,"%s:rol_1_4_dmawait",host_name); printf("Book hist: %s \n",hist_name); rol_1[4] = new TH1D(hist_name,hist_name, 500, -0.5, 499.5); ALL_1D_HIST->Add(rol_1[4]); //-- reset PED monitor array for (int i=0; i<(21*72); i++) { pedmon[i].status=0; pedmon[i].mean=0.; pedmon[i].sigma=0.; pedmon[i].updated=0; } //--- F250 --- MAXCHAN=16; MAXSLOT=21; MAXBIN=MAXSLOT*MAXCHAN; F250scalers=NULL; for (int is=0; isSetMarkerStyle(20); adc_f250_prof->SetMarkerSize(0.3); adc_f250_prof->SetMarkerColor(2); ALL_1D_HIST->Add(adc_f250_prof); sprintf(hist_name,"%s:F250_pedestals",host_name); printf("Book hist: %s \n",hist_name); ped_f250_prof = new TProfile(hist_name,hist_name,MAXBIN,-0.5,MAXBIN-0.5,0.,200.,"s"); ped_f250_prof->SetMarkerStyle(20); ped_f250_prof->SetMarkerSize(0.3); ped_f250_prof->SetMarkerColor(2); ALL_1D_HIST->Add(ped_f250_prof); sprintf(hist_name,"%s:F250_pedmean",host_name); printf("Book hist: %s \n",hist_name); f250_pedmean = new TH1D(hist_name,hist_name, 100, 79.5, 119.5); f250_pedmean->SetFillStyle( 1001); f250_pedmean->SetFillColor( kYellow); ALL_1D_HIST->Add(f250_pedmean); sprintf(hist_name,"%s:F250_pedsigma",host_name); printf("Book hist: %s \n",hist_name); f250_pedsigma = new TH1D(hist_name,hist_name, 50, -0.5, 9.5); ALL_1D_HIST->Add(f250_pedsigma); f250_pulse_len=110; //-- bins sprintf(hist_name,"%s:F250_pulse",host_name); printf("Book hist: %s \n",hist_name); f250_pulse = new TH1D(hist_name,hist_name, f250_pulse_len, -0.5, f250_pulse_len-0.5); ALL_1D_HIST->Add(f250_pulse); sprintf(hist_name,"%s:F250_time",host_name); printf("Book hist: %s \n",hist_name); f250_time = new TH1D(hist_name,hist_name, f250_pulse_len, -0.5, f250_pulse_len-0.5); ALL_1D_HIST->Add(f250_time); //--- F125 --- MAXCHAN_f125=72; MAXSLOT_f125=21; MAXBIN_f125=MAXSLOT_f125*MAXCHAN_f125; for (int is=0; isSetMarkerStyle(20); ped_f125_prof->SetMarkerSize(0.3); ped_f125_prof->SetMarkerColor(2); ALL_1D_HIST->Add(ped_f125_prof); // //f125_pulse_len=412; //-- bins f125_pulse_len=500; //-- bins ; maximum 1024 bin, also input buffer is 1024 => BUFFERLEVEL=1 => RAW mode if (!strncmp(host_name,"roccdc",6)) { f125_pulse_len=220; } else if (!strncmp(host_name,"rocfdc",6)) { f125_pulse_len=110; } else if (!strncmp(host_name,"roctrd",6)) { f125_pulse_len=500; } sprintf(hist_name,"%s:F125_pulse",host_name); printf("Book hist: %s \n",hist_name); f125_pulse = new TH1D(hist_name,hist_name, f125_pulse_len, -0.5, f125_pulse_len-0.5); f125_pulse->GetXaxis()->SetTitle("FADC bin"); f125_pulse->GetYaxis()->SetTitle("Amplitude, adu"); ALL_1D_HIST->Add(f125_pulse); // sprintf(hist_name,"%s:F125_gpulse",host_name); printf("Book hist: %s \n",hist_name); f125_gpulse = new TH1D(hist_name,hist_name, f125_pulse_len, -0.5, f125_pulse_len-0.5); f125_gpulse->GetXaxis()->SetTitle("FADC bin"); f125_gpulse->GetYaxis()->SetTitle("Amplitude, adu"); ALL_1D_HIST->Add(f125_gpulse); // sprintf(hist_name,"%s:F125_wpulse",host_name); printf("Book hist: %s \n",hist_name); f125_wpulse = new TH1D(hist_name,hist_name, f125_pulse_len, -0.5, f125_pulse_len-0.5); f125_wpulse->GetXaxis()->SetTitle("FADC bin"); f125_wpulse->GetYaxis()->SetTitle("Amplitude, adu"); ALL_1D_HIST->Add(f125_wpulse); // sprintf(hist_name,"%s:F125_time",host_name); printf("Book hist: %s \n",hist_name); f125_time = new TH1D(hist_name,hist_name, f125_pulse_len, 1.5, f125_pulse_len+1.5); f125_time->GetXaxis()->SetTitle("FADC bin"); f125_time->GetYaxis()->SetTitle("Entries"); ALL_1D_HIST->Add(f125_time); // sprintf(hist_name,"%s:F125_stime",host_name); printf("Book hist: %s \n",hist_name); f125_stime = new TH1D(hist_name,hist_name, f125_pulse_len, 1.5, f125_pulse_len+1.5); f125_stime->GetXaxis()->SetTitle("FADC bin"); f125_stime->GetYaxis()->SetTitle("Entries"); ALL_1D_HIST->Add(f125_stime); // sprintf(hist_name,"%s:F125_wtime",host_name); printf("Book hist: %s \n",hist_name); f125_wtime = new TH1D(hist_name,hist_name, f125_pulse_len, 1.5, f125_pulse_len+1.5); f125_wtime->GetXaxis()->SetTitle("FADC bin"); f125_wtime->GetYaxis()->SetTitle("Entries"); ALL_1D_HIST->Add(f125_wtime); // sprintf(hist_name,"%s:F125_gtime",host_name); printf("Book hist: %s \n",hist_name); f125_gtime = new TH1D(hist_name,hist_name, f125_pulse_len, 1.5, f125_pulse_len+1.5); f125_gtime->GetXaxis()->SetTitle("FADC bin"); f125_gtime->GetYaxis()->SetTitle("Entries"); ALL_1D_HIST->Add(f125_gtime); // sprintf(hist_name,"%s:F125_fe55",host_name); printf("Book hist: %s \n",hist_name); f125_fe55 = new TH1D(hist_name,hist_name, 4000, 0.5, 4000.5); f125_fe55->GetXaxis()->SetTitle("Ampl"); f125_fe55->GetYaxis()->SetTitle("Entries"); ALL_1D_HIST->Add(f125_fe55); // sprintf(hist_name,"%s:F125_gem",host_name); printf("Book hist: %s \n",hist_name); f125_gem = new TH1D(hist_name,hist_name, 4000, 0.5, 4000.5); f125_gem->GetXaxis()->SetTitle("Ampl"); f125_gem->GetYaxis()->SetTitle("Entries"); ALL_1D_HIST->Add(f125_gem); //--- CAEN TDC --- MAXCHAN_CAEN=32; MAXSLOT_CAEN=21; MAXBIN_CAEN=MAXSLOT_CAEN*MAXCHAN_CAEN; for (int is=0; isAdd(tdc_prof_caen); //--- F1TDC --- MAXCHAN_F1TDC=32; if (strncmp(host_name,"rocfdc",6)==0 || strncmp(host_name,"rocbcdc",6)==0) MAXCHAN_F1TDC=48; MAXSLOT_F1TDC=21; MAXBIN_F1TDC=MAXSLOT_F1TDC*MAXCHAN_F1TDC; // for (int is=0; isAdd(tdc_prof_f1tdc); // sprintf(hist_name,"%s:F1TDC_occup",host_name); printf("Book hist: %s \n",hist_name); tdc_occup_f1tdc = new TH1D(hist_name,hist_name,MAXBIN_F1TDC,-0.5,MAXBIN_F1TDC-0.5); ALL_1D_HIST->Add(tdc_occup_f1tdc); sprintf(hist_name,"%s:F1TDC_RF",host_name); printf("Book hist: %s \n",hist_name); int RFbins=15000; tdc_rf_f1tdc = new TH1D(hist_name,hist_name,RFbins,-0.5,RFbins-0.5); ALL_1D_HIST->Add(tdc_rf_f1tdc); // //---- DIRC scalers ----- DIRCscalers=NULL; DIRCdata=NULL; //---- DISCR scalers ----- DISCRscalers=NULL; ResetFlag=1; sprintf(hist_name,"%s:DISCR_slots",host_name); Tdsc = new TTree(hist_name,hist_name); Tdsc->SetDirectory(0); // -- memory resident Tdsc->Branch("Nslots", &Nslots, "Nslots/I"); Tdsc->Branch("Dslots", Dslots, "Dslots[Nslots]/I"); ALL_NT_HIST->Add(Tdsc); sprintf(hist_name,"%s:DISCR_rates",host_name); Trate = new TTree(hist_name,hist_name); Trate->SetDirectory(0); // -- memory resident Trate->Branch("Dtime", &Dtime, "Dtime/D"); Trate->Branch("Nslots", &Nslots, "Nslots/I"); Trate->Branch("DscRate", DscRate, "DscRate[Nslots][16]/F"); //Trate->Branch("pDscRate", pDscRate, "pDscRate[21*16]/F"); ALL_NT_HIST->Add(Trate); //char host_name[80]; //gethostname(host_name, 80); //char hist_name_ch[80], hist_name_sl[80], hist_name_cr[80]; //sprintf(hist_name_cr,"%s_F250_Scalers",host_name); //F250scalers = new TH2F(hist_name_cr,hist_name_cr,MAXSLOT,0.5,MAXSLOT+0.5,MAXCHAN,0.5,MAXCHAN+0.5); for (int is=0; iscd(); INIT=1; ROOT_WRITE_LOCK =0; } //----------------------------------------------------------------------------------------- // RESET ALL HISTS //----------------------------------------------------------------------------------------- int Hist::Reset_Hist(int runnum, int flag) { ROOT_WRITE_LOCK = 1; printf(" INFO::: HIST Reset():: LOCK=%d runnum=%d flag=%d\n",ROOT_WRITE_LOCK,runnum,flag); if (Debug>6) ALL_1D_HIST->Print(); TObject *obj; TH1 *h1; //--- root file --- char name[256]; if (runnum>0 && flag==0) { sprintf(name,"~/ROOT_HIST/RootHist_%s_Run_%d_%d.root",host_name,runnum,1); printf("***********************************************************************\n"); printf("****************** open HISTS in File=%s \n",name); printf("***********************************************************************\n"); //root_file = NULL; root_file = new TFile(name,"RECREATE"); if (root_file) { Tdsc->SetDirectory(root_file); Trate->SetDirectory(root_file); } TIter next0(ALL_RUN_HIST); while ((obj = next0())) { if (Debug>1) obj->Print(); h1=(TH1 *) obj; h1->Reset(" "); } } TIter next1(ALL_1D_HIST); while ((obj = next1())) { if (Debug>1) obj->Print(); h1=(TH1 *) obj; h1->Reset(" "); } TH2 *h2; TIter next2(ALL_2D_HIST); while ((obj = next2())) { if (Debug>1) obj->Print(); h2=(TH2 *) obj; h2->Reset(" "); } printf("RESET HIST: flag=%d Nfits=%d \n",flag,Nfits); if (flag==0) { //--- only prestart Nfits=0; } else if (flag==1) { //--- Calibration //if (Nfits<(MAX_FIT-1)) Nfits++; return 1; //-- reset only 1D hist -- } //--------------------------------------------------------- TH1 *hf; TIter next5(ALL_FIT_HIST); while ((obj = next5())) { if (Debug>1) obj->Print(); hf=(TH1 *) obj; hf->Reset(" "); } TProfile *hp; TIter next3(ALL_Prof_HIST); while ((obj = next3())) { if (Debug>1) obj->Print(); hp=(TProfile *) obj; hp->Reset(" "); } printf("RESET NT: flag=%d Nfits=%d Lock=%d \n",flag,Nfits,ROOT_WRITE_LOCK); /* // do not reset discr/slot information TTree *nt; TIter next4(ALL_NT_HIST); while ((obj = next4())) { if (Debug>1) obj->Print(); nt=(TTree *) obj; nt->Reset(" "); } */ Trate->Print(); Trate->Reset(" "); Trate->Print(); ROOT_WRITE_LOCK = 0; return 0; } //----------------------------------------------------------------------------------------- // Save Histos //----------------------------------------------------------------------------------------- int Hist::Save_Hists(int flag, int DAC) { char name[256]; int icc; ROOT_WRITE_LOCK = 1; if (root_file && DAC==0) { printf("****************** SAVE TREES in File= \n"); root_file->cd(); Tdsc->Write(); Trate->Write(); root_file->Write(); Tdsc->SetDirectory(NULL); Trate->SetDirectory(NULL); //Trate->Reset(" "); root_file->Close(); } sprintf(name,"~/ROOT_HIST/RootHist_%s_Run_%d_%d.root",host_name,flag,DAC); printf("***********************************************************************\n"); printf("****************** SAVE HISTS in File=%s \n",name); printf("***********************************************************************\n"); TFile f1(name,"RECREATE"); f1.cd(); TObject *obj; printf("Save ALL_RUN_HIST \n"); TIter next0(ALL_RUN_HIST); icc=0; while ((obj = next0())) { icc++; //printf("ICC=%d obj=%p\n",icc,obj); if (obj) { if (Debug>1) obj->Print(); obj->Write(); } else { printf("ALL_RUN_HIST:: ICC=%d zero pointer !!!\n",icc); } } printf("Save ALL_1D_HIST \n"); TIter next1(ALL_1D_HIST); icc=0; while ((obj = next1())) { icc++; //printf("ICC=%d obj=%p\n",icc,obj); if (obj) { if (Debug>1) obj->Print(); obj->Write(); } else { printf("ALL_1D_HIST:: ICC=%d zero pointer !!!\n",icc); } } printf("Save ALL_2D_HIST \n"); TIter next2(ALL_2D_HIST); icc=0; while ((obj = next2())) { icc++; //printf("next2::ICC=%d\n",icc); if (Debug>1) obj->Print(); obj->Write(); } TProfile *hp; printf("Save ALL_Prof_HIST \n"); TIter next3(ALL_Prof_HIST); while ((obj = next3())) { obj->Print(); obj->Write(); } /* printf("Save ALL_NT_HIST \n"); TIter next4(ALL_NT_HIST); icc=0; while ((obj = next4())) { icc++; //printf("next4::ICC=%d\n",icc); if (Debug>1) obj->Print(); obj->Write(); } */ f1.Write(); f1.Close(); printf("Close root file \n"); ROOT_WRITE_LOCK = 0; } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- // TEST FILL scalers //----------------------------------------------------------------------------------------- int Hist::f250_scalers_fill(int rate) { //---- dummy scalers ---- double ran; F250scalers->Reset(" "); for (int is=0; is 14 ) continue; for (int ic=0; icRndm()*rate/2.+2*rate; else ran = rndm->Gaus(rate,15); //printf("Fill scalers:: ran=%f\n",ran); F250scalers->SetBinContent(is+1,ic+1,ran); } } F250scalers->SetEntries(1); //------ } //----------------------------------------------------------------------------------------- // TEST FILL ped //----------------------------------------------------------------------------------------- int Hist::ped_fill(int ped) { double rp = rndm->Gaus(ped,10); for (int is=0; isFill_F250_adc(is,ic,rp+is-ic); } } } //----------------------------------------------------------------------------------------- int Hist::test_fill() { // Loop forever while filling the hists //cout<Rndm()-0.5)*2.0; double y = (rndm->Rndm()-0.5)*2.0; double z = 6.0; double p = rndm->Landau(0.5, 0.075); // total momentum double m = 0.134; double Etot = sqrt(p*p + m*m) + rndm->Gaus(0.0, 0.005); px = p*x/z; py = p*y/z; pz = sqrt(p*p*(1.0 - (x*x+y*y)/(z*z))); E = Etot; Mass = sqrt(Etot*Etot - p*p); if (!h_px) { //-- first call, Book hist -- h_px = new TH1D("px", "Momentum X-component", 500, 0.0, 10.0); h_py = new TH1D("py", "Momentum Y-component", 500, 0.0, 10.0); h_pz = new TH1D("pz", "Momentum Z-component", 500, 0.0, 10.0); h_E = new TH1D("E", "Energy", 500, 0.0, 10.0); h_Mass = new TH1D("Mass", "Mass", 1000, 0.0, 2.0); for(int i=0; i< 100; i++) data[i] = (float)i; // Define some trees to save T = new TTree("T", "Event Info"); T->Branch("px", &px, "px/D"); T->Branch("py", &py, "py/D"); T->Branch("pz", &pz, "pz/D"); T->Branch("E", &E, "E/D"); T->Branch("Mass", &Mass, "Mass/D"); T->Branch("data", &data, "data[100]/F"); // Set nice labels for X-axes h_px->SetXTitle("p_{x} (GeV/c)"); h_py->SetXTitle("p_{y} (GeV/c)"); h_pz->SetXTitle("p_{z} (GeV/c)"); h_E->SetXTitle("Energy (GeV)"); h_Mass->SetXTitle("mass (GeV/c^2)"); } h_px->Fill(px); h_py->Fill(py); h_pz->Fill(pz); h_E->Fill(E); h_Mass->Fill(Mass); // Limit how large the TTree can get if(NeventsFill(); }else if(Nevents == MAX_TREE_EVENTS){ cout << MAX_TREE_EVENTS/1000 << "k events in tree. Only histograms will be filled from here on." << endl; } if(((++Nevents) % 100)==0){ //gDirectory->ls(); cout <<" "<