added ConvertTimeOffset() and event window only open when sn == 0 and ch == 15

This commit is contained in:
Ryan Tang 2024-10-23 16:07:41 -04:00
parent 554247e046
commit 4eab257a01
2 changed files with 48 additions and 11 deletions

View File

@ -47,9 +47,13 @@ inline unsigned int getTime_us(){
//^================================================
///============ time offset
std::vector<int64_t> timeOffsetList = {0, 0, 0, 0}; // in ps
// std::vector<uint64_t> timeOffsetList = {100863280000, 100562004000, 320120000, 0}; //in ps // run34
int bufferSize = 5000000;
std::vector<double> timeOffsetListSec = {0.0008849, 0.000359944, 0.000268992, 0.0}; // run 29
std::vector<uint64_t> timeOffsetList = {0, 0, 0, 0}; // in ps
int bufferSize = 10000000;
//^================================================
@ -82,6 +86,20 @@ std::vector<std::pair<int, std::string>> 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<Data> hitList_A ;
std::vector<Data> 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<Data> event;
@ -305,8 +332,12 @@ int main(int argc, char **argv) {
}
}
ret = ReadBatch(bufferSize);
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;
}
}

View File

@ -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);