fixed Eventbuilder for forward eventbuilding and 2D cut loading
This commit is contained in:
parent
6123e307d8
commit
188d65897a
|
@ -755,7 +755,7 @@ inline void Histogram2D::LoadCuts(QString cutFileName){
|
|||
int colorID = tempCutID% colorCycle.count();
|
||||
text->setColor(colorCycle[colorID].first);
|
||||
cutTextIDList.push_back(itemCount() - 1);
|
||||
// cutList.push_back(tempCut);
|
||||
cutList.push_back(tempCut);
|
||||
cutIDList.push_back(tempCutID);
|
||||
}
|
||||
tempCut.clear();
|
||||
|
@ -795,7 +795,7 @@ inline void Histogram2D::LoadCuts(QString cutFileName){
|
|||
// Close the file
|
||||
file.close();
|
||||
qDebug() << "File read successfully from" << cutFileName;
|
||||
qDebug() << " NUmber of cut loaded " << numCut;
|
||||
qDebug() << " Number of cut loaded " << numCut << ", " << cutList.count();
|
||||
|
||||
// PrintCutEntry();
|
||||
// DrawCut();
|
||||
|
|
181
MultiBuilder.cpp
181
MultiBuilder.cpp
|
@ -95,6 +95,8 @@ void MultiBuilder::PrintAllEvent(){
|
|||
}
|
||||
}
|
||||
|
||||
//^############################################### forward event builder
|
||||
|
||||
void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
|
||||
DebugPrint("%s", "MultiBuilder");
|
||||
earlistTime = -1;
|
||||
|
@ -103,9 +105,7 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
|
|||
nExhaushedCh = 0;
|
||||
for( int i = 0; i < nData; i++){
|
||||
|
||||
for( int j = 0; j < data[i]->GetNChannel(); j++ ) {
|
||||
chExhaused[i][j] = false;
|
||||
}
|
||||
for( int j = 0; j < data[i]->GetNChannel(); j++ ) chExhaused[i][j] = false;
|
||||
|
||||
for(unsigned int ch = 0; ch < data[i]->GetNChannel(); ch ++){
|
||||
|
||||
|
@ -118,7 +118,7 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
|
|||
}
|
||||
|
||||
if( data[i]->GetTimestamp(ch, index) == 0 ||
|
||||
loopIndex[i][ch] * dataSize[i] > data[i]->GetLoopIndex(ch) * dataSize[i] + data[i]->GetDataIndex(ch)) {
|
||||
loopIndex[i][ch] * dataSize[i] + nextIndex[i][ch] > data[i]->GetLoopIndex(ch) * dataSize[i] + data[i]->GetDataIndex(ch)) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[i][ch] = true;
|
||||
continue;
|
||||
|
@ -138,42 +138,6 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
|
|||
}
|
||||
|
||||
if( verbose ) printf("%s | bd : %d, ch : %d, %llu\n", __func__, earlistDigi, earlistCh, earlistTime);
|
||||
|
||||
}
|
||||
|
||||
void MultiBuilder::FindLatestTimeAndCh(bool verbose){
|
||||
DebugPrint("%s", "MultiBuilder");
|
||||
latestTime = 0;
|
||||
latestDigi = -1;
|
||||
latestCh = -1;
|
||||
|
||||
nExhaushedCh = 0;
|
||||
|
||||
for( int i = 0; i < nData; i++){
|
||||
|
||||
for( int j = 0; j < data[i]->GetNChannel(); j++ ) chExhaused[i][j] = false;
|
||||
|
||||
for(unsigned int ch = 0; ch < data[i]->GetNChannel(); ch ++){
|
||||
|
||||
if( nextIndex[i][ch] < 0 || data[i]->GetDataIndex(ch) < 0 || nextIndex[i][ch] <= lastBackWardIndex[i][ch] ) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[i][ch] = true;
|
||||
// printf(", exhanshed. %d \n", nExhaushedCh);
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned long long time = data[i]->GetTimestamp(ch, nextIndex[i][ch]);
|
||||
// printf(", time : %llu\n", time );
|
||||
if( time > latestTime ) {
|
||||
latestTime = time;
|
||||
latestDigi = i;
|
||||
latestCh = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose ) printf("%s | bd : %d, ch : %d, %llu\n", __func__, latestDigi, latestCh, latestTime);
|
||||
|
||||
}
|
||||
|
||||
void MultiBuilder::FindEarlistTimeAmongLastData(bool verbose){
|
||||
|
@ -195,35 +159,16 @@ void MultiBuilder::FindEarlistTimeAmongLastData(bool verbose){
|
|||
}
|
||||
if( verbose ) printf("%s | bd : %d, ch : %d, %lld \n", __func__, latestDigi, latestCh, latestTime);
|
||||
}
|
||||
|
||||
void MultiBuilder::FindLatestTimeOfData(bool verbose){
|
||||
DebugPrint("%s", "MultiBuilder");
|
||||
latestTime = 0;
|
||||
latestCh = -1;
|
||||
latestDigi = -1;
|
||||
for( int i = 0; i < nData; i++){
|
||||
// printf("%s | digi-%d-th | %d\n", __func__, i, data[i]->GetNChannel());
|
||||
for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){
|
||||
int index = data[i]->GetDataIndex(ch);
|
||||
// printf("ch-%2d | index : %d \n", ch, index);
|
||||
if( index == -1 ) continue;
|
||||
if( data[i]->GetTimestamp(ch, index) > latestTime ) {
|
||||
latestTime = data[i]->GetTimestamp(ch, index);
|
||||
latestCh = ch;
|
||||
latestDigi = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( verbose ) printf("%s | bd : %d, ch : %d, %lld \n", __func__, latestDigi, latestCh, latestTime);
|
||||
}
|
||||
|
||||
|
||||
void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
||||
DebugPrint("%s", "MultiBuilder");
|
||||
|
||||
FindEarlistTimeAndCh(verbose); //Give the earliest time, ch, digi
|
||||
|
||||
FindEarlistTimeAmongLastData(verbose); // give lastest Time, Ch, and Digi for event building
|
||||
|
||||
FindEarlistTimeAndCh(verbose); //Give the earliest time, ch, digi
|
||||
if( earlistCh == -1 || nExhaushedCh == nData * MaxNChannels) return; /// no data
|
||||
if( earlistCh == -1 || nExhaushedCh == numTotCh) return; /// no data
|
||||
|
||||
eventBuilt = 0;
|
||||
//======= Start building event
|
||||
|
@ -235,14 +180,13 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
eventIndex ++;
|
||||
if( eventIndex >= MaxNEvent ) eventIndex = 0;
|
||||
events[eventIndex].clear();
|
||||
|
||||
em.Clear();
|
||||
|
||||
for( int k = 0; k < nData; k++){
|
||||
int bd = (k + earlistDigi) % nData;
|
||||
|
||||
// printf("##### %d/%d | ", k, nData);
|
||||
// data[k]->PrintAllData(true, 10);
|
||||
// printf("##### %d/%d | ", bd, nData);
|
||||
// data[bd]->PrintAllData(true);
|
||||
|
||||
const int numCh = data[bd]->GetNChannel();
|
||||
|
||||
|
@ -250,17 +194,22 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
int ch = (i + earlistCh ) % numCh;
|
||||
// printf("ch : %d | exhaused ? %s \n", ch, chExhaused[bd][ch] ? "Yes" : "No");
|
||||
if( chExhaused[bd][ch] ) continue;
|
||||
if( loopIndex[bd][ch] * dataSize[bd] + nextIndex[bd][ch] > data[bd]->GetLoopIndex(ch) * dataSize[bd] + data[bd]->GetDataIndex(ch)) {
|
||||
|
||||
// printf(" ch : %2d | %d(%d) | %d(%d)\n", ch, loopIndex[bd][ch], nextIndex[bd][ch], data[bd]->GetLoopIndex(ch), data[bd]->GetDataIndex(ch) );
|
||||
|
||||
if( nextIndex[bd][ch] == -1
|
||||
|| loopIndex[bd][ch] * dataSize[bd] + nextIndex[bd][ch] > data[bd]->GetLoopIndex(ch) * dataSize[bd] + data[bd]->GetDataIndex(ch)) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[bd][ch] = true;
|
||||
|
||||
// printf(" ch : %d exhaused\n", ch);
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
if ( nextIndex[bd][ch] < 0 ) break; // hotfix
|
||||
unsigned long long time = data[bd]->GetTimestamp(ch, nextIndex[bd][ch]);
|
||||
//printf("%6ld, sn: %5d, ch: %2d, timestamp : %16llu | earlistTime : %16llu | timeWindow : %u \n", eventIndex, data[bd]->boardSN, ch, time, earlistTime, timeWindow);
|
||||
// printf("%6d, sn: %5d, ch: %2d, timestamp : %16llu | earlistTime : %16llu | timeWindow : %u \n", nextIndex[bd][ch], data[bd]->boardSN, ch, time, earlistTime, timeWindow);
|
||||
|
||||
if( time >= earlistTime && (time - earlistTime <= timeWindow) ){
|
||||
em.sn = snList[bd];
|
||||
|
@ -281,14 +230,21 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
}else{
|
||||
break;
|
||||
}
|
||||
if( timeWindow <= 0 ) break;
|
||||
if( timeWindow == 0 ) break;
|
||||
}while( true );
|
||||
if( timeWindow <= 0 ) break;
|
||||
if( timeWindow == 0 ) break;
|
||||
}
|
||||
if( timeWindow <= 0 ) break;
|
||||
if( timeWindow == 0 ) break;
|
||||
}
|
||||
|
||||
if( events[eventIndex].size() == 0 ) continue;
|
||||
if( events[eventIndex].size() == 0 ) {
|
||||
if( eventIndex > 1) {
|
||||
eventIndex --;
|
||||
}else{
|
||||
eventIndex = MaxNEvent - 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if( events[eventIndex].size() > 1) {
|
||||
std::sort(events[eventIndex].begin(), events[eventIndex].end(), [](const Hit& a, const Hit& b) {
|
||||
|
@ -296,21 +252,21 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
});
|
||||
}
|
||||
|
||||
lastEventTime = events[eventIndex].back().timestamp;
|
||||
// lastEventTime = events[eventIndex].back().timestamp;
|
||||
|
||||
///Find the next earlist
|
||||
FindEarlistTimeAndCh(false);
|
||||
|
||||
// //if there is a time jump, say, bigger than TimeJump. break
|
||||
if( earlistTime - lastEventTime > timeJump ) {
|
||||
if( verbose ){
|
||||
printf("!!!!!!!! Time Jump detected stop event building and get more data.\n");
|
||||
printf("event index : %6lu, earlist time : %16llu\n", eventIndex, earlistTime);
|
||||
printf(" %6s last event time : %16llu \n", "", lastEventTime);
|
||||
printf(" %6s time jump > %16llu \n", "", timeJump);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// if( earlistTime - lastEventTime > timeJump ) {
|
||||
// if( verbose ){
|
||||
// printf("!!!!!!!! Time Jump detected stop event building and get more data.\n");
|
||||
// printf("event index : %6lu, last event time : %16llu\n", eventIndex, lastEventTime);
|
||||
// printf(" %6s earilest time : %16llu \n", "", earlistTime);
|
||||
// printf(" %6s time jump > %16llu \n", "", timeJump);
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
|
||||
eventBuilt ++;
|
||||
totalEventBuilt ++;
|
||||
|
@ -330,7 +286,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
printf("%05d, %02d | %5d | %5d %llu \n", sn, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp);
|
||||
}
|
||||
|
||||
if( nExhaushedCh == nData * MaxNChannels ) {
|
||||
if( nExhaushedCh == numTotCh ) {
|
||||
printf("######################### no more event to be built\n");
|
||||
break;
|
||||
}
|
||||
|
@ -349,12 +305,67 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
break;
|
||||
}
|
||||
}
|
||||
}while(nExhaushedCh < nData * MaxNChannels);
|
||||
}while(nExhaushedCh < numTotCh);
|
||||
|
||||
forceStop = false;
|
||||
|
||||
}
|
||||
|
||||
//^############################################### backward event builder
|
||||
|
||||
void MultiBuilder::FindLatestTimeAndCh(bool verbose){
|
||||
DebugPrint("%s", "MultiBuilder");
|
||||
latestTime = 0;
|
||||
latestDigi = -1;
|
||||
latestCh = -1;
|
||||
|
||||
nExhaushedCh = 0;
|
||||
|
||||
for( int i = 0; i < nData; i++){
|
||||
for( int j = 0; j < data[i]->GetNChannel(); j++ ) chExhaused[i][j] = false;
|
||||
|
||||
for(unsigned int ch = 0; ch < data[i]->GetNChannel(); ch ++){
|
||||
if( nextIndex[i][ch] < 0 || data[i]->GetDataIndex(ch) < 0 || nextIndex[i][ch] <= lastBackWardIndex[i][ch] ) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[i][ch] = true;
|
||||
// printf(", exhanshed. %d \n", nExhaushedCh);
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned long long time = data[i]->GetTimestamp(ch, nextIndex[i][ch]);
|
||||
// printf(", time : %llu\n", time );
|
||||
if( time > latestTime ) {
|
||||
latestTime = time;
|
||||
latestDigi = i;
|
||||
latestCh = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose ) printf("%s | bd : %d, ch : %d, %llu\n", __func__, latestDigi, latestCh, latestTime);
|
||||
}
|
||||
|
||||
void MultiBuilder::FindLatestTimeOfData(bool verbose){
|
||||
DebugPrint("%s", "MultiBuilder");
|
||||
latestTime = 0;
|
||||
latestCh = -1;
|
||||
latestDigi = -1;
|
||||
for( int i = 0; i < nData; i++){
|
||||
// printf("%s | digi-%d-th | %d\n", __func__, i, data[i]->GetNChannel());
|
||||
for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){
|
||||
int index = data[i]->GetDataIndex(ch);
|
||||
// printf("ch-%2d | index : %d \n", ch, index);
|
||||
if( index == -1 ) continue;
|
||||
if( data[i]->GetTimestamp(ch, index) > latestTime ) {
|
||||
latestTime = data[i]->GetTimestamp(ch, index);
|
||||
latestCh = ch;
|
||||
latestDigi = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( verbose ) printf("%s | bd : %d, ch : %d, %lld \n", __func__, latestDigi, latestCh, latestTime);
|
||||
}
|
||||
|
||||
void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
|
||||
DebugPrint("%s", "MultiBuilder");
|
||||
//skip trace, and only build for maxNumEvent events max
|
||||
|
|
|
@ -140,12 +140,12 @@ void Analyzer::SetDatabase(QString IP, QString Name, QString Token){
|
|||
influx = nullptr;
|
||||
}
|
||||
}else{
|
||||
printf("Database name : %s NOT found.\n", dataBaseName.toStdString().c_str());
|
||||
printf(RED "Database name : %s NOT found.\n" RESET, dataBaseName.toStdString().c_str());
|
||||
delete influx;
|
||||
influx = nullptr;
|
||||
}
|
||||
}else{
|
||||
printf("InfluxDB URL (%s) is NOT Valid. \n", dataBaseIP.toStdString().c_str());
|
||||
printf(RED "InfluxDB URL (%s) is NOT Valid. \n" RESET, dataBaseIP.toStdString().c_str());
|
||||
delete influx;
|
||||
influx = nullptr;
|
||||
}
|
||||
|
|
|
@ -69,13 +69,13 @@ public slots:
|
|||
void startTimer(){
|
||||
// printf("start timer\n");
|
||||
mb->ForceStop(false);
|
||||
mb->ClearEvents();
|
||||
anaTimer->start(waitTimeinSec*1000);
|
||||
}
|
||||
void stopTimer(){
|
||||
// printf("stop worker\n");
|
||||
anaTimer->stop();
|
||||
mb->ForceStop(true);
|
||||
mb->ClearEvents();
|
||||
}
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -15,7 +15,6 @@ class Cross : public Analyzer{
|
|||
public:
|
||||
Cross(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
|
||||
|
||||
|
||||
SetUpdateTimeInSec(1.0);
|
||||
|
||||
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
|
||||
|
@ -27,8 +26,6 @@ public:
|
|||
|
||||
SetDatabase("http://localhost:8086/", "testing", "zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A==");
|
||||
|
||||
printf(" %p \n", influx);
|
||||
|
||||
SetUpCanvas(); // see below
|
||||
|
||||
};
|
||||
|
@ -65,6 +62,7 @@ private:
|
|||
unsigned long long t1, t4, t7;
|
||||
|
||||
QPushButton * bnClearHist;
|
||||
QLabel * lbInfluxIP;
|
||||
|
||||
};
|
||||
|
||||
|
@ -107,6 +105,16 @@ inline void Cross::SetUpCanvas(){
|
|||
hMulti->Clear();
|
||||
});
|
||||
|
||||
QString haha;
|
||||
if( influx ) {
|
||||
haha = dataBaseIP + ", DB : " + dataBaseName;
|
||||
}else{
|
||||
haha = "No influxDB connection.";
|
||||
}
|
||||
lbInfluxIP = new QLabel( haha , this);
|
||||
if( influx == nullptr ) lbInfluxIP->setStyleSheet("color : red;");
|
||||
layout->addWidget(lbInfluxIP, row, 1, 1, 3);
|
||||
|
||||
row ++;
|
||||
hdEE = new Histogram2D("dE vs E", "E[ch]", "dE[ch]", 500, -100, 5000, 500, -100, 5000, this);
|
||||
layout->addWidget(hdEE, row, 0, 1, 2);
|
||||
|
@ -150,12 +158,6 @@ inline void Cross::UpdateHistograms(){
|
|||
if( eventBuilt == 0 ) return;
|
||||
|
||||
//============ Get the cut list, if any
|
||||
/*
|
||||
QList<QPolygonF> cutList = hPID->GetCutList();
|
||||
const int nCut = cutList.count();
|
||||
unsigned long long tMin[nCut] = {0xFFFFFFFFFFFFFFFF}, tMax[nCut] = {0};
|
||||
unsigned int count[nCut]={0};
|
||||
*/
|
||||
QList<QPolygonF> cutList1 = hdEE->GetCutList();
|
||||
const int nCut1 = cutList1.count();
|
||||
printf(" >>>>>> num of cut = %d, event Size : %ld\n", nCut1, eventBuilt);
|
||||
|
|
11
macro.h
11
macro.h
|
@ -1,7 +1,7 @@
|
|||
#ifndef MACRO_H
|
||||
#define MACRO_H
|
||||
|
||||
#define MaxNPorts 1 //for optical link
|
||||
#define MaxNPorts 2 //for optical link
|
||||
#define MaxNBoards 2 //for both optical link and usb
|
||||
|
||||
#define MaxNDigitizer MaxNPorts * MaxNBoards
|
||||
|
@ -19,6 +19,15 @@
|
|||
|
||||
#define SETTINGSIZE 2048
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define BLUE "\033[34m"
|
||||
#define MAGENTA "\033[35m"
|
||||
#define CYAN "\033[36m"
|
||||
#define WHITE "\033[37m"
|
||||
|
||||
#define DAQLockFile "DAQLock.dat"
|
||||
#define PIDFile "pid.dat"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user