diff --git a/.gitignore b/.gitignore index 6c3fec6..fa16a30 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ test example read-set + +*.root diff --git a/DataBlock.h b/DataBlock.h index cf89e4d..32600be 100644 --- a/DataBlock.h +++ b/DataBlock.h @@ -8,29 +8,38 @@ #include #include +#include "TSystem.h" +#include "TObject.h" +#include "TFile.h" +#include "TTree.h" +#include "TString.h" + +#define MAX_TRACE_LENGHT 16000 + class DataBlock{ public: - unsigned short ch; - unsigned short slot; - unsigned short crate; - unsigned short headerLength; /// headerLength > 4, more data except tarce. - unsigned short eventLength; /// eventLength = headerLength + trace - bool pileup; - unsigned long long time; - unsigned short cfd; - unsigned short energy; - unsigned short trace_length; - bool trace_out_of_range; + UShort_t ch; + UShort_t slot; + UShort_t crate; + UShort_t headerLength; /// headerLength > 4, more data except tarce. + UShort_t eventLength; /// eventLength = headerLength + trace + Bool_t pileup; + ULong64_t time; + UShort_t cfd; + UShort_t energy; + UShort_t trace_length; + Bool_t trace_out_of_range; - int trailing; - int leading; - int gap; - int baseline; - int QDCsum[8]; + Int_t trailing; + Int_t leading; + Int_t gap; + Int_t baseline; + Int_t QDCsum[8]; - unsigned long long eventID; - unsigned short trace[4000]; + ULong64_t eventID; + + UShort_t trace[MAX_TRACE_LENGHT]; DataBlock(){ Clear(); @@ -50,7 +59,6 @@ public: energy = 0; trace_length = 0; trace_out_of_range = 0; - eventID = 0; ClearQDC(); ClearTrace(); @@ -65,13 +73,13 @@ public: } void ClearTrace(){ - for( int i = 0; i < 1024; i++) trace[i] = 0; + for( int i = 0 ; i < MAX_TRACE_LENGHT; i++) trace[i] = 0; } void Print(bool printTrace = false){ printf("============== eventID : %llu\n", eventID); - printf("Crate: %d, Slot: %d, Ch: %d \n", crate, slot, ch); + printf("Crate: %d, Slot: %d, Ch: %d \n", crate, slot, ch); printf("HeaderLength: %d, Event Length: %d, energy: %d, timeStamp: %llu\n", headerLength, eventLength, energy, time); printf("trace_length: %d, pile-up:%d\n", trace_length, pileup); if( headerLength > 4 ){ diff --git a/Makefile b/Makefile index 4a56c9f..01ead00 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,8 @@ LIBS = $(APIBASE)libPixie16Api.so $(APIBASE)libPixieSDK.a $(PLXBASE)PlxApi.a all: test example -example : example.o Pixie16Class.o - $(CC) $(INCFLAGS) example.o Pixie16Class.o $(LIBS) -o example +example : example.o + $(CC) $(INCFLAGS) example.o $(LIBS) -o example example.o : example.cpp $(CC) $(CFLAGS) $(INCFLAGS) example.cpp diff --git a/Pixie16Class.cpp b/Pixie16Class.cpp index 63997d2..e12443e 100644 --- a/Pixie16Class.cpp +++ b/Pixie16Class.cpp @@ -230,6 +230,25 @@ void Pixie16::AdjustOffset(){ } +void Pixie16::CaptureBaseLine(unsigned short modID, unsigned short ch){ + retval = Pixie16AcquireBaselines(modID); + if( CheckError("Pixie16AcquireBaselines::MOD::"+std::to_string(modID)) < 0 ) return; + + retval = Pixie16ReadSglChanBaselines(Baselines, TimeStamps, 3640, modID, ch); + if( CheckError("Pixie16ReadSglChanBaselines::MOD::"+std::to_string(modID) + "CH::"+std::to_string(ch)) < 0 ) return; + +} + +void Pixie16::CaptureADCTrace(unsigned short modID, unsigned short ch){ + + retval = Pixie16AcquireADCTrace (modID); + if( CheckError("Pixie16AcquireADCTrace") < 0 ) return; + + retval = Pixie16ReadSglChanADCTrace (ADCTrace, 8192, modID, ch); + if( CheckError("Pixie16ReadSglChanADCTrace") < 0 ) return; + +} + void Pixie16::StartRun(bool listMode){ unsigned short mode = NEW_RUN; //RESUME_RUN @@ -270,27 +289,26 @@ void Pixie16::StopRun(){ void Pixie16::ReadData(unsigned short modID){ if( Pixie16CheckRunStatus(modID) == 1){ - unsigned int oldnFIFOWords = nFIFOWords; retval = Pixie16CheckExternalFIFOStatus (&nFIFOWords, modID); if( CheckError("Pixie16CheckExternalFIFOStatus") < 0 ) return; - if(nFIFOWords *1.0 / EXTERNAL_FIFO_LENGTH > 0.2) { - //if(nFIFOWords > 0) { + ///if(nFIFOWords *1.0 / EXTERNAL_FIFO_LENGTH > 0.2) { + if(nFIFOWords > 0) { printf("\033[1;31m####### READ DATA \033[m: number of word in module-%d FIFO : %d \n", modID, nFIFOWords); if( ExtFIFO_Data != NULL ) delete ExtFIFO_Data; ExtFIFO_Data = new unsigned int [nFIFOWords]; retval = Pixie16ReadDataFromExternalFIFO(ExtFIFO_Data, nFIFOWords, modID); CheckError("Pixie16ReadDataFromExternalFIFO"); - nextWord = nextWord - oldnFIFOWords; } }else{ printf("Pixie16 is not running.\n"); } } -void Pixie16::ProcessSingleData(){ +bool Pixie16::ProcessSingleData(){ + + bool breakProcessLoopFlag = false; if( nextWord < nFIFOWords ){ - data->ch = ExtFIFO_Data[nextWord] & 0xF ; data->slot = (ExtFIFO_Data[nextWord] >> 4) & 0xF; data->crate = (ExtFIFO_Data[nextWord] >> 8) & 0xF; @@ -299,7 +317,7 @@ void Pixie16::ProcessSingleData(){ data->pileup = ExtFIFO_Data[nextWord] >> 31 ; data->eventID ++; - if( nextWord + data->eventLength < nFIFOWords ){ + if( nextWord + data->eventLength <= nFIFOWords ){ data->time = ((unsigned long long)(ExtFIFO_Data[nextWord+2] & 0xFFFF) << 32) + ExtFIFO_Data[nextWord+1]; data->cfd = ExtFIFO_Data[nextWord + 2] >> 16 ; @@ -312,8 +330,6 @@ void Pixie16::ProcessSingleData(){ data->trace[2*i+0] = ExtFIFO_Data[nextWord + data->headerLength + i] & 0xFFFF ; data->trace[2*i+1] = (ExtFIFO_Data[nextWord + data->headerLength + i] >> 16 ) & 0xFFFF ; } - }else{ - data->ClearTrace(); } }else{ data->time = 0; @@ -324,52 +340,14 @@ void Pixie16::ProcessSingleData(){ } nextWord += data->eventLength ; - } + + if( nextWord == nFIFOWords ) {nextWord = 0; breakProcessLoopFlag = true;} + if( nextWord > nFIFOWords ) {nextWord = nextWord - nFIFOWords; breakProcessLoopFlag = true;} -} - -void Pixie16::ProcessData(int verbose){ - - if( verbose >= 2 ) for( unsigned int i = 0; i < nFIFOWords; i++) printf("%5d|%X|\n", i, ExtFIFO_Data[nextWord+i]); - - while( nextWord < nFIFOWords ){ - ProcessSingleData(); - if( verbose >= 1 ) data->Print(0); - if( verbose >= 3 ) data->Print(1); /// print trace } -} + return breakProcessLoopFlag ; -void Pixie16::GetTrace(unsigned short modID, unsigned short ch){ - - unsigned short ADCTrace[8192]; - retval = Pixie16AcquireADCTrace (modID); - if( CheckError("Pixie16AcquireADCTrace") < 0 ) return; - - retval = Pixie16ReadSglChanADCTrace (ADCTrace, 8192, modID, ch); - if( CheckError("Pixie16ReadSglChanADCTrace") < 0 ) return; - - for( int i = 0; i < 8192 ; i++){ - printf("%4d, %d \n", i, ADCTrace[i]); - } -} - - -void Pixie16::GetBaseLines(unsigned short modID, unsigned short ch){ - - retval = Pixie16AcquireBaselines(modID); - if( CheckError("Pixie16AcquireBaselines") < 0 ) return; - - - double Baselines[3640], TimeStamps[3640]; - - retval = Pixie16ReadSglChanBaselines(Baselines, TimeStamps, 3640, modID, ch); - if( CheckError("Pixie16ReadSglChanBaselines") < 0 ) return; - - for( int i = 0; i < 3640; i++){ - printf("%4d, %.4f, %.4f \n", i, Baselines[i], TimeStamps[i]); - } - } unsigned int Pixie16::GetDigitizerSetting(std::string parName, unsigned short modID, bool verbose){ diff --git a/Pixie16Class.h b/Pixie16Class.h index 454247e..3763ce9 100644 --- a/Pixie16Class.h +++ b/Pixie16Class.h @@ -68,27 +68,13 @@ private: unsigned int * ExtFIFO_Data; unsigned int * Statistics; + double Baselines[3640], TimeStamps[3640]; ///for baseline + unsigned short ADCTrace[8192]; + DataBlock * data; unsigned int nextWord; std::ofstream outFile; - - /*** - struct channelSetting{ - double trigger_risetime; - double trigger_flattop; - double trigger_threshold; - double energy_risetime; - double energy_flattop; - double tau; - double trace_length; - double trace_delay; - double V_offset; - double XDT; - double baseline_percent; - double energy_minumum; //EMIN - double baseline_cut; //BLCUT - };**/ public: @@ -108,6 +94,14 @@ public: void BootDigitizers(); void AdjustOffset(); + void CaptureBaseLine(unsigned short modID, unsigned short ch); + int GetBaslineLength() {return 3640;} + double * GetBasline() {return Baselines;} + double * GetBaselineTimestamp() {return TimeStamps;} + + void CaptureADCTrace(unsigned short modID, unsigned short ch); + int GetADCTraceLength() {return 8192;} + unsigned short * GetADCTrace() {return ADCTrace;} ///========================= Setting @@ -172,28 +166,21 @@ public: double GetLiveTime(unsigned short modID, unsigned short ch); double GetOutputCountRate(unsigned short modID, unsigned short ch); double GetRealTime(unsigned short modID); - void PrintStatistics(unsigned short modID); - - void GetTrace(unsigned short modID, unsigned short ch); - void GetBaseLines(unsigned short modID, unsigned short ch); + void PrintStatistics(unsigned short modID); + void ReadData(unsigned short modID); - void PrintExtFIFOData(int a) { printf("%5d-%5d | %08X %08X %08X %08X \n", a, a+3, ExtFIFO_Data[a], ExtFIFO_Data[a+1], ExtFIFO_Data[a+2], ExtFIFO_Data[a+3]);} unsigned int GetnFIFOWords() {return nFIFOWords;} unsigned int GetNextWord() {return nextWord;} - DataBlock * GetData() {return data;} - void ProcessSingleData(); - void ProcessData(int verbose = 0); + DataBlock * GetData() {return data;} + bool ProcessSingleData(); void OpenFile(std::string fileName, bool append); void SaveData(); void CloseFile(); - //void SaveData(char * fileName, unsigned short isEndOfRun); - - }; #endif diff --git a/evtReader.h b/evtReader.h index 7202bce..ab8855c 100644 --- a/evtReader.h +++ b/evtReader.h @@ -14,7 +14,7 @@ #include "TString.h" #include "TBenchmark.h" -#include "DataBlock.h" +#include "../armory/DataBlock.h" #define MAX_CRATES 2 #define MAX_BOARDS_PER_CRATE 13 @@ -37,7 +37,7 @@ class evtReader{ long int nBlock; unsigned int extraHeader[14]; - unsigned int traceBlock[4000]; + unsigned int traceBlock[MAX_TRACE_LENGHT/2]; TBenchmark gClock; @@ -119,6 +119,8 @@ void evtReader::OpenFile(TString inFileName){ gClock.Reset(); gClock.Start("timer"); + + isOpened = true; } }; @@ -135,7 +137,7 @@ bool evtReader::IsEndOfFile() { } -int evtReader::ReadBlock(int opt = 0){ +int evtReader::ReadBlock(int opt){ if( feof(inFile) ) return -1; if( endOfFile ) return -1; @@ -164,10 +166,8 @@ int evtReader::ReadBlock(int opt = 0){ data->trace_length = (header[3] >> 16) & 0x7FFF; data->trace_out_of_range = header[3] >> 31; - //data->id = data->crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (data->slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + data->ch; - //data->detID = mapping[data->id]; - data->ClearQDC(); + data->ClearTrace(); ///======== read QDCsum if( data->headerLength >= 4 ){ @@ -193,15 +193,16 @@ int evtReader::ReadBlock(int opt = 0){ data->baseline = 0; } ///====== read trace - if( data->eventLength > data->headerLength ){ + if( data->eventLength > data->headerLength ){ fread(traceBlock, sizeof(unsigned int) * ( data->trace_length / 2 ), 1, inFile); - + for( int i = 0; i < data->trace_length/2 ; i++){ - data->trace[2*i+0] = traceBlock[i] & 0xFFFF ; + data->trace[2*i+0] = traceBlock[i] & 0xFFFF ; data->trace[2*i+1] = (traceBlock[i] >> 16 ) & 0xFFFF ; } ///make QDC by trace + /** if( data->headerLength == 4 || data->headerLength == 8 ) { for( int i = 0; i < 8; i++){ data->QDCsum[i] = 0;} for( int i = 0; i < data->trace_length; i++){ @@ -214,7 +215,7 @@ int evtReader::ReadBlock(int opt = 0){ if( 160 <= i && i < 175 ) data->QDCsum[6] += data->trace[i]; if( 175 <= i && i < 200 ) data->QDCsum[7] += data->trace[i]; } - } + }*/ } } diff --git a/example.cpp b/example.cpp index f83c70e..ec75d63 100644 --- a/example.cpp +++ b/example.cpp @@ -308,7 +308,7 @@ bool execute_list_mode_run(const configuration& cfg, const double& runtime_in_se std::vector output_streams(cfg.num_modules()); for (unsigned short i = 0; i < cfg.num_modules(); i++) { - output_streams[i] = new std::ofstream(generate_filename(i, "list-mode", "bin"), + output_streams[i] = new std::ofstream(generate_filename(i, "list-mode", "evt"), std::ios::out | std::ios::binary); } diff --git a/test.cpp b/test.cpp index 207eb7f..3ce8d24 100644 --- a/test.cpp +++ b/test.cpp @@ -77,7 +77,8 @@ int main(int argc, char *argv[]){ TH1F * hch = new TH1F("hch", "channel", 16, 0, 16); TH1F * hE = new TH1F("hE", "energy", 400, 0, 30000); TGraph * gTrace = new TGraph(); - gTrace->GetXaxis()->SetTitle("time [ch, 1 ch = 4 ns]"); + gTrace->GetXaxis()->SetTitle("time [ch]"); + //pixie->SetDigitizerPresetRunTime(100000, 0); //pixie->SetDigitizerSynchWait(0, 0); // not simultaneously @@ -94,7 +95,7 @@ int main(int argc, char *argv[]){ */ int ch = 6; - double time = 0.5; ///sec + double time = 2.0; ///sec /* for( int i = 0; i < 16; i++){ @@ -104,26 +105,47 @@ int main(int argc, char *argv[]){ pixie->SetChannelVOffset(0, 0, i); } * */ + //pixie->AdjustOffset(); + //pixie->SetChannelEnergyRiseTime(2, 0, ch); - pixie->SetChannelTriggerThreshold(300, 0, ch); + //pixie->SetChannelTriggerThreshold(300, 0, ch); //pixie->SetChannelEnergyTau(50, 0, ch); //pixie->SetChannelOnOff(true, 0, ch); //pixie->SetChannelPositivePolarity(true, 0, ch); //pixie->SetChannelTraceOnOff(true, 0, ch); - pixie->SetChannelVOffset(-1.0, 0, ch); - pixie->SetChannelTraceLenght(10, 0, ch); - pixie->SetChannelTraceDelay(2, 0, ch); - pixie->SaveSettings("test_ryan.set"); + //pixie->SetChannelBaseLinePrecent(10, 0, ch); + //pixie->SetChannelVOffset(0.0, 0, ch); + //pixie->SetChannelTraceLenght(10, 0, ch); + //pixie->SetChannelTraceDelay(2, 0, ch); + //pixie->SaveSettings("test_ryan.set"); pixie->PrintChannelAllSettings(0, ch); pixie->PrintChannelsMainSettings(0); - printf("start run for %f sec\n", time); - //pixie->AdjustOffset(); + //pixie->CaptureADCTrace(0, ch); + //unsigned short * haha = pixie->GetADCTrace(); + //for( int i = 0 ; i < pixie->GetADCTraceLength(); i++){ + // gTrace->SetPoint(i, i, haha[i]); + //} + //canvas->cd(3); gTrace->Draw("APL"); + + + //pixie->CaptureBaseLine(0, ch); + //double * baseline = pixie->GetBasline(); + //double * baselineTime = pixie->GetBaselineTimestamp(); + //for( int i = 0 ; i < pixie->GetBaslineLength(); i++){ + // gTrace->SetPoint(i, baselineTime[i]*1000, baseline[i]); + // //printf("%5d | %f, %f \n", i, baselineTime[i]*1000, baseline[i]); + //} + //canvas->cd(3); gTrace->Draw("APL"); + + + + printf("start run for %f sec\n", time); uint32_t StartTime = get_time(), CurrentTime = get_time(); pixie->StartRun(1); @@ -136,19 +158,18 @@ int main(int argc, char *argv[]){ while( pixie->GetNextWord() < pixie->GetnFIFOWords() ){ - //for( int i = pixie->GetNextWord(); i < pixie->GetNextWord() + 314 ; i++) pixie->PrintExtFIFOData(i); - pixie->ProcessSingleData(); - //data->Print(0); - //printf("--------------next word : %d (%d) | event lenght : %d \n", pixie->GetNextWord(), pixie->GetnFIFOWords(), data->eventLength); - + bool breakFlag = pixie->ProcessSingleData(); + data->Print(0); + printf("--------------next word : %d (%d) | event lenght : %d \n", pixie->GetNextWord(), pixie->GetnFIFOWords(), data->eventLength); + hch->Fill( data->ch); hE->Fill( data->energy ); if( data->trace_length > 0 ) { for( int i = 0 ; i < data->trace_length; i++){ gTrace->SetPoint(i, i, data->trace[i]); - //if( i % 200 == 0 ) printf("%i, %d \n", i, data->trace[i]); } + gTrace->GetYaxis()->SetRangeUser(0, 5000); canvas->cd(3); gTrace->Draw("APL"); } @@ -158,6 +179,7 @@ int main(int argc, char *argv[]){ canvas->Update(); gSystem->ProcessEvents(); + if( breakFlag ) break; } CurrentTime = get_time(); diff --git a/test_ryan.set b/test_ryan.set index ba45f96..d8e153e 100644 --- a/test_ryan.set +++ b/test_ryan.set @@ -98,7 +98,7 @@ 16544, 16544, 16544, - 16544, + 16548, 16804, 16544, 16544, @@ -423,7 +423,7 @@ 32768, 32768, 32768, - 10922, + 32768, 32768, 32768, 32768, @@ -1016,7 +1016,7 @@ "ChanNum": 0, "CoincPattern": 0, "CoincWait": 0, - "ControlTask": 5, + "ControlTask": 0, "CrateID": 0, "FIFOLength": 8188, "FastFilterRange": 0,