diff --git a/Bin2Root2.cpp b/Bin2Root2.cpp index ee3f1ea..58ec972 100644 --- a/Bin2Root2.cpp +++ b/Bin2Root2.cpp @@ -47,9 +47,13 @@ inline unsigned int getTime_us(){ //^================================================ ///============ time offset -std::vector timeOffsetList = {0, 0, 0, 0}; // in ps +// std::vector timeOffsetList = {100863280000, 100562004000, 320120000, 0}; //in ps // run34 -int bufferSize = 5000000; +std::vector timeOffsetListSec = {0.0008849, 0.000359944, 0.000268992, 0.0}; // run 29 + +std::vector timeOffsetList = {0, 0, 0, 0}; // in ps + +int bufferSize = 10000000; //^================================================ @@ -82,6 +86,20 @@ std::vector> findDataFiles(const std::string& patter return results; } +void ConvertTimeOffset(){ + + double tMax = 0; + for( size_t i = 0; i < timeOffsetListSec.size(); i++ ) { + if( tMax < timeOffsetListSec[i] ) tMax = timeOffsetListSec[i]; + } + + printf("############ Time Offset \n"); + for( size_t i = 0; i < timeOffsetList.size(); i++ ) { + timeOffsetList[i] = uint64_t( ( tMax - timeOffsetListSec[i] ) * 1e12); + printf("%zu | %lu ps = %.3f msec\n", i, timeOffsetList[i],timeOffsetList[i] / 1e9); + } + +} std::vector hitList_A ; std::vector hitList_B ; @@ -89,6 +107,8 @@ BinReader * reader = nullptr; int ReadBatch(int bufferSize){ + printf("Reading Batch %d \n", bufferSize); + if( hitList_A.size() == 0 ){ for( int i = 0 ; i < bufferSize; i++ ){ if( reader->ReadBlock() != 1 ){ @@ -124,7 +144,10 @@ int ReadBatch(int bufferSize){ }); } - if( hitList_B.size() == 0 ) return 1; + if( hitList_B.size() == 0 ) { + printf("hitList_B is empty. end of ReadBatch\n"); + return 1; + } uint64_t t0_A = hitList_A.front().TimeStamp; uint64_t t1_A = hitList_A.back().TimeStamp; @@ -226,6 +249,9 @@ int main(int argc, char **argv) { printf(" Max multiplity = %d hits/event (hard coded)\n", MAX_MULTI); printf(" Out file name = %s \n", outFileName.Data()); printf(" Buffer Size = %d\n", bufferSize); + + ConvertTimeOffset(); + printf("=============================== Number of input Files : %d \n", nFile); for( int i = 0 ; i < nFile; i++ ){ printf(" %3d | %s\n", i, inFileName[i].second.c_str()); @@ -286,7 +312,8 @@ int main(int argc, char **argv) { const uint16_t header = reader->data.Header; int ret = 0; - uint64_t t0 = -1; + bool windowOpen = false; + uint64_t t0 = 0; std::vector event; @@ -305,8 +332,12 @@ int main(int argc, char **argv) { } } ret = ReadBatch(bufferSize); - if( tStart == 0 ) tStart = hitList_A[0].TimeStamp; - tEnd = hitList_A.back().TimeStamp; + if( hitList_A.size() > 0 ) { + unsigned long dtA = (hitList_A.back().TimeStamp - hitList_A.front().TimeStamp)/ 1000; + printf("hitList A | size %zu | timeRange %ld ns = %.3f sec\n", hitList_A.size(), dtA/100, dtA/1e12 ); + if( tStart == 0 ) tStart = hitList_A[0].TimeStamp; + tEnd = hitList_A.back().TimeStamp; + } //build event from hitList_A; for( size_t i = 0; i < hitList_A.size(); i++){ @@ -324,12 +355,16 @@ int main(int argc, char **argv) { }else{ - if( t0 == -1 ) { + // if( t0 == -1 ) { + if( !windowOpen && (hitList_A[i].BoardID == 0 && hitList_A[i].Channel == 15 ) ){ // for MUSICS, use the grid to open time window t0 = hitList_A[i].TimeStamp; + windowOpen = true; event.push_back(hitList_A[i]); continue; } + if( !windowOpen ) continue; + if( hitList_A[i].TimeStamp - t0 < timeWindow ){ event.push_back(hitList_A[i]); }else{ @@ -356,8 +391,10 @@ int main(int argc, char **argv) { // start a new event event.clear(); - t0 = hitList_A[i].TimeStamp; - event.push_back(hitList_A[i]); + // t0 = hitList_A[i].TimeStamp; + // event.push_back(hitList_A[i]); + t0 = 0; // for MUSICS + windowOpen = false; } } diff --git a/BinReader.h b/BinReader.h index 6c8f72d..8c4e1be 100644 --- a/BinReader.h +++ b/BinReader.h @@ -52,7 +52,7 @@ struct Data{ printf(" Flag : 0x%08X\n", Flags); if( (Header & 0x8 ) >= 1 ){ /// is waevform exist printf(" Wave form code : %d , nSample : %d\n", WaveformCode, NSample); - for( int i = 0 ; i < NSample ; i++){ + for( unsigned int i = 0 ; i < NSample ; i++){ printf("%4d | %d \n", i, Trace[i]); } } @@ -305,7 +305,7 @@ int BinReader::ReadBlock(int skipTrace){ if( skipTrace == 0 ){ // if ( fread(data.Trace, sizeof(data.Trace), 1, inFile) != 1 ) endOfFile = IsEndOfFile(); - for( int i = 0; i < data.NSample; i++ ){ + for( unsigned int i = 0; i < data.NSample; i++ ){ uint16_t haha; size_t dummy = fread(&haha, 2, 1, inFile); data.Trace.push_back(haha);