Compare commits
2 Commits
367512ae06
...
322cbca165
Author | SHA1 | Date | |
---|---|---|---|
|
322cbca165 | ||
|
197a49f678 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@ test
|
|||
test_indep
|
||||
programSettings.txt
|
||||
EventBuilder
|
||||
DataGenerator
|
||||
|
||||
data
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "CAENDigitizerType.h"
|
||||
#include "macro.h"
|
||||
|
||||
#define MaxNData 10000 /// store 100k events per channels
|
||||
#define MaxNData 10000 /// store 10k events per channels
|
||||
|
||||
class Data{
|
||||
|
||||
|
@ -272,8 +272,8 @@ inline void Data::PrintAllData() const{
|
|||
printf("============================= Print Data\n");
|
||||
for( int ch = 0; ch < MaxNChannels ; ch++){
|
||||
if( DataIndex[ch] < 0 ) continue;
|
||||
printf("------------ ch : %d, %d \n", ch, DataIndex[ch]);
|
||||
for( int ev = 0; ev <= DataIndex[ch] ; ev++){
|
||||
printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]);
|
||||
for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){
|
||||
if( DPPType == V1730_DPP_PHA_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
if( DPPType == V1730_DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <cstdio>
|
||||
#include <random>
|
||||
|
||||
#include "macro.h"
|
||||
#include "ClassDigitizer.h"
|
||||
|
@ -6,7 +7,60 @@
|
|||
|
||||
int main(){
|
||||
|
||||
Digitizer * digi = new Digitizer();
|
||||
|
||||
Data * data = digi->GetData();
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
std::uniform_int_distribution<int> RanNext(0, 1);
|
||||
std::uniform_int_distribution<int> RanCh(0, 4);
|
||||
std::uniform_int_distribution<unsigned short> RanEnergy(1, 1000);
|
||||
std::uniform_int_distribution<unsigned long long> RanTime(1, 50);
|
||||
|
||||
OnlineEventBuilder * eb = new OnlineEventBuilder(digi);
|
||||
unsigned long long time = 0;
|
||||
|
||||
for( int q = 0; q < 3; q ++ ){
|
||||
int count = 0;
|
||||
do{
|
||||
|
||||
int ch = RanCh(gen);
|
||||
unsigned short energy = RanEnergy(gen);
|
||||
|
||||
unsigned long long timestamp = time + RanTime(gen) + RanNext(gen)*100;
|
||||
time = timestamp;
|
||||
|
||||
count ++;
|
||||
|
||||
data->DataIndex[ch] ++;
|
||||
if( data->DataIndex[ch] > MaxNData ) {
|
||||
data->LoopIndex[ch] ++;
|
||||
data->DataIndex[ch] = 0;
|
||||
}
|
||||
int index = data->DataIndex[ch];
|
||||
|
||||
// if( ch == 2 && index > 2) {
|
||||
// data->DataIndex[ch] --;
|
||||
// continue;
|
||||
// }
|
||||
data->Energy[ch][index] = energy;
|
||||
data->Timestamp[ch][index] = timestamp;
|
||||
|
||||
printf("%02d | %5d %10lld\n", ch, energy, time);
|
||||
|
||||
}while( count < 40 );
|
||||
|
||||
data->PrintAllData();
|
||||
|
||||
printf("===================================\n");
|
||||
|
||||
eb->BuildEvents(100, true);
|
||||
|
||||
}
|
||||
|
||||
delete eb;
|
||||
delete digi;
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
|
|||
|
||||
OBJS = ClassDigitizer.o OnlineEventBuilder.o
|
||||
|
||||
ALL = test test_indep EventBuilder
|
||||
ALL = test test_indep EventBuilder DataGenerator
|
||||
|
||||
#########################################################################
|
||||
|
||||
|
@ -40,3 +40,7 @@ test_indep : test_indep.cpp RegisterAddress.h macro.h
|
|||
EventBuilder : EventBuilder.cpp ClassData.h
|
||||
@echo "--------- making EventBuilder"
|
||||
$(CC) $(COPTS) -o EventBuilder EventBuilder.cpp $(CAENLIBS) $(ROOTLIBS)
|
||||
|
||||
DataGenerator : DataGenerator.cpp ClassDigitizer.o OnlineEventBuilder.o
|
||||
@echo "--------- making DataGenerator"
|
||||
$(CC) $(COPTS) -o DataGenerator DataGenerator.cpp ClassDigitizer.o OnlineEventBuilder.o $(CAENLIBS)
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#include "OnlineEventBuilder.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){
|
||||
|
||||
data = digi->GetData();
|
||||
nCh = digi->GetNChannels();
|
||||
|
||||
eventIndex = -1;
|
||||
isNeverBuild = true;
|
||||
for( int i = 0; i < MaxNEvent; i++ ) events[i].clear();
|
||||
|
||||
for( int i = 0; i < MaxNChannels; i++ ){
|
||||
|
@ -29,10 +30,8 @@ OnlineEventBuilder::~OnlineEventBuilder(){
|
|||
|
||||
void OnlineEventBuilder::FindEarlistTimeAndCh(){
|
||||
|
||||
if( isNeverBuild ){
|
||||
earlistTime = -1;
|
||||
earlistCh = -1;
|
||||
}
|
||||
earlistTime = -1;
|
||||
earlistCh = -1;
|
||||
|
||||
nExhaushedCh = 0;
|
||||
for( int i = 0; i < MaxNChannels; i++ ){
|
||||
|
@ -46,33 +45,42 @@ void OnlineEventBuilder::FindEarlistTimeAndCh(){
|
|||
continue;
|
||||
}
|
||||
|
||||
if( isNeverBuild || nextIndex[ch] == -1 ) nextIndex[ch] = 0;
|
||||
if( nextIndex[ch] == -1 ) nextIndex[ch] = 0;
|
||||
|
||||
unsigned long long time = data->Timestamp[ch][nextIndex[ch]];
|
||||
|
||||
if( time < earlistTime ) {
|
||||
earlistTime = time;
|
||||
earlistCh = ch;
|
||||
printf("ch: %d , nextIndex : %d, %llu\n", ch, nextIndex[ch] , earlistTime);
|
||||
//printf("ch: %d , nextIndex : %d, %llu\n", ch, nextIndex[ch] , earlistTime);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::FindLatestTime(){
|
||||
|
||||
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){
|
||||
latestTime = 0;
|
||||
for( unsigned ch = 0; ch < nCh; ch++ ){
|
||||
int index = data->DataIndex[ch];
|
||||
if( index == -1 ) continue;
|
||||
if( data->Timestamp[ch][index] > latestTime ) {
|
||||
latestTime = data->Timestamp[ch][index];
|
||||
}
|
||||
}
|
||||
|
||||
printf("--- latest time %lld \n", latestTime);
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
|
||||
|
||||
this->timeWindow = timeWindow;
|
||||
|
||||
//======= Find the earlist time and ch
|
||||
FindLatestTime();
|
||||
FindEarlistTimeAndCh();
|
||||
|
||||
if( earlistCh == -1 ) { /// no data
|
||||
return;
|
||||
}
|
||||
|
||||
//======= Start bilding event
|
||||
if( earlistCh == -1 || nExhaushedCh == nCh) return; /// no data
|
||||
|
||||
//======= Start building event
|
||||
do{
|
||||
|
||||
eventIndex ++;
|
||||
|
@ -92,15 +100,16 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){
|
|||
|
||||
do {
|
||||
|
||||
dT = data->Timestamp[ch][nextIndex[ch]] - earlistTime;
|
||||
unsigned long long time = data->Timestamp[ch][nextIndex[ch]];
|
||||
|
||||
if( dT < timeWindow ){
|
||||
if( time - earlistTime < timeWindow ){
|
||||
dp.ch = ch;
|
||||
dp.energy = data->Energy[ch][nextIndex[ch]];
|
||||
dp.timeStamp = data->Timestamp[ch][nextIndex[ch]];
|
||||
dp.timeStamp = time;
|
||||
|
||||
events[eventIndex].push_back(dp);
|
||||
nextIndex[ch]++;
|
||||
if( nextIndex[ch] >= MaxNData) nextIndex[ch] = 0;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
@ -109,35 +118,33 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){
|
|||
|
||||
}
|
||||
|
||||
isNeverBuild = false;
|
||||
|
||||
//===== print
|
||||
std::sort(events[eventIndex].begin(), events[eventIndex].end(), [](const dataPoint& a, const dataPoint& b) {
|
||||
return a.timeStamp < b.timeStamp;
|
||||
});
|
||||
|
||||
printf("######################################### Event ID : %ld\n", eventIndex);
|
||||
for( int i = 0; i <(int) events[eventIndex].size(); i++){
|
||||
printf("%02d | %5d %llu \n", events[eventIndex][i].ch, events[eventIndex][i].energy, events[eventIndex][i].timeStamp);
|
||||
}
|
||||
|
||||
|
||||
///Find the next earlist
|
||||
earlistTime = data->Timestamp[dp.ch][nextIndex[dp.ch]];
|
||||
FindEarlistTimeAndCh();
|
||||
|
||||
if( nExhaushedCh == nCh ) {
|
||||
printf("######################### no more eevent to be built\n");
|
||||
if( verbose ){
|
||||
printf(">>>>>>>>>>>>>>>>>>>>>>>>> Event ID : %ld\n", eventIndex);
|
||||
for( int i = 0; i <(int) events[eventIndex].size(); i++){
|
||||
printf("%02d | %5d %llu \n", events[eventIndex][i].ch, events[eventIndex][i].energy, events[eventIndex][i].timeStamp);
|
||||
}
|
||||
|
||||
if( nExhaushedCh == nCh ) {
|
||||
printf("######################### no more event to be built\n");
|
||||
break;
|
||||
}
|
||||
printf("----- next ch : %d, next earlist Time : %llu \n", earlistCh, earlistTime);
|
||||
}
|
||||
|
||||
if( latestTime - earlistTime <= timeWindow ) {
|
||||
if( verbose ) {
|
||||
printf("######################### left over data for next build\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
printf("----- next ch : %d, next earlist Time : %llu \n", earlistCh, earlistTime);
|
||||
|
||||
}while(nExhaushedCh < nCh);
|
||||
|
||||
for( unsigned int i = 0; i < nCh; i ++ ) printf("%d | exhaushed ? %d \n", i, chExhaused[i] );
|
||||
printf("------ nExhaushedCh = %d \n", nExhaushedCh);
|
||||
|
||||
|
||||
//TODO ----- to speed up continue with data->DataIndex
|
||||
data->ClearData();
|
||||
for( int i = 0 ; i < MaxNChannels; i++) nextIndex[i] = -1;
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ public:
|
|||
OnlineEventBuilder(Digitizer * digi);
|
||||
~OnlineEventBuilder();
|
||||
|
||||
void BuildEvents(unsigned short timeWindow);
|
||||
void BuildEvents(unsigned short timeWindow, bool verbose = false);
|
||||
|
||||
long eventIndex;
|
||||
std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy
|
||||
|
@ -41,7 +41,6 @@ private:
|
|||
Data * data;
|
||||
|
||||
unsigned short timeWindow;
|
||||
bool isNeverBuild;
|
||||
int nextIndex[MaxNChannels];
|
||||
|
||||
int nExhaushedCh;
|
||||
|
@ -49,6 +48,8 @@ private:
|
|||
unsigned long long earlistTime;
|
||||
int earlistCh;
|
||||
void FindEarlistTimeAndCh();
|
||||
unsigned long long latestTime;
|
||||
void FindLatestTime();
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user