added single or list support for MultiBuilder, added but not test Backward event building
This commit is contained in:
parent
dd9459a47f
commit
8daeb362c5
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -10,6 +10,9 @@ DataGenerator
|
|||
|
||||
data
|
||||
|
||||
*.d
|
||||
*.pcm
|
||||
|
||||
*.txt
|
||||
|
||||
*~
|
||||
|
|
17
Analyser.cpp
17
Analyser.cpp
|
@ -32,6 +32,11 @@ Analyzer::~Analyzer(){
|
|||
delete mb;
|
||||
}
|
||||
|
||||
void Analyzer::RedefineEventBuilder(std::vector<int> idList){
|
||||
delete mb;
|
||||
mb = new MultiBuilder(digi, idList);
|
||||
}
|
||||
|
||||
void Analyzer::StartThread(){
|
||||
mb->ClearEvents();
|
||||
buildTimerThread->start();
|
||||
|
@ -44,11 +49,19 @@ void Analyzer::StopThread(){
|
|||
buildTimerThread->wait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Analyzer::BuildEvents(){
|
||||
|
||||
for( unsigned int i = 0; i < nDigi; i++ ) digiMTX[digiID].lock();
|
||||
unsigned int nData = mb->GetNumOfDigitizer();
|
||||
std::vector<int> idList = mb->GetDigiIDList();
|
||||
for( unsigned int i = 0; i < nData; i++ ) digiMTX[idList[i]].lock();
|
||||
if( isBuildBackward ){
|
||||
mb->BuildEventsBackWard(0);
|
||||
}else{
|
||||
mb->BuildEvents(0, 0, 0);
|
||||
for( unsigned int i = 0; i < nDigi; i++ ) digiMTX[digiID].unlock();
|
||||
}
|
||||
for( unsigned int i = 0; i < nData; i++ ) digiMTX[idList[i]].unlock();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
|
||||
MultiBuilder * GetEventBuilder() { return mb;}
|
||||
|
||||
void RedefineEventBuilder(std::vector<int> idList);
|
||||
void SetBackwardBuild(bool TF) { isBuildBackward = TF;}
|
||||
|
||||
public slots:
|
||||
void StartThread();
|
||||
|
@ -57,18 +59,16 @@ private slots:
|
|||
protected:
|
||||
QGridLayout * layout;
|
||||
void BuildEvents();
|
||||
void SetDigiID(int ID) { digiID = ID;}
|
||||
void SetUpdateTimeInSec(double sec = 1.0) {waitTimeinSec = sec; buildTimerThread->SetWaitTimeinSec(waitTimeinSec);}
|
||||
|
||||
private:
|
||||
Digitizer ** digi;
|
||||
unsigned short nDigi;
|
||||
|
||||
int digiID; // the digi that will event
|
||||
double waitTimeinSec;
|
||||
|
||||
MultiBuilder * mb;
|
||||
|
||||
bool isBuildBackward;
|
||||
TimingThread * buildTimerThread;
|
||||
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ void DataReaderScript(){
|
|||
Data * data = new Data();
|
||||
data->DPPType = V1730_DPP_PSD_CODE;
|
||||
|
||||
std::string fileName = "temp_036_089_PSD_000.fsu";
|
||||
std::string fileName = "temp_030_089_PSD_000.fsu";
|
||||
|
||||
FILE * haha = fopen(fileName.c_str(), "r");
|
||||
fseek(haha, 0L, SEEK_END);
|
||||
|
@ -49,8 +49,8 @@ void DataReaderScript(){
|
|||
|
||||
}while(!feof(haha) && ftell(haha) < inFileSize);
|
||||
|
||||
data->PrintStat();
|
||||
data->PrintAllData();
|
||||
data->PrintStat();
|
||||
|
||||
fclose(haha);
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ int main(int argc, char **argv) {
|
|||
TFile * outRootFile = new TFile(outFileName, "recreate");
|
||||
TTree * tree = new TTree("tree", outFileName);
|
||||
|
||||
unsigned long long evID = 0;
|
||||
unsigned long long evID = -1;
|
||||
unsigned short multi = 0;
|
||||
unsigned short bd[MAX_MULTI] = {0}; /// boardID
|
||||
unsigned short ch[MAX_MULTI] = {0}; /// chID
|
||||
|
@ -222,7 +222,7 @@ int main(int argc, char **argv) {
|
|||
if( startIndex < 0 ) startIndex += MaxNEvent;
|
||||
//printf("startIndex : %ld, %ld\n", startIndex, mb->eventIndex);
|
||||
for( long i = startIndex; i <= mb->eventIndex; i++){
|
||||
evID = i;
|
||||
evID ++;
|
||||
multi = mb->events[i].size();
|
||||
for( int j = 0; j < multi; j ++){
|
||||
bd[j] = mb->events[i][j].bd;
|
||||
|
@ -260,7 +260,7 @@ int main(int argc, char **argv) {
|
|||
if( startIndex < 0 ) startIndex += MaxNEvent;
|
||||
//printf("startIndex : %ld, %ld\n", startIndex, mb->eventIndex);
|
||||
for( long i = startIndex; i <= mb->eventIndex; i++){
|
||||
evID = i;
|
||||
evID ++;
|
||||
multi = mb->events[i].size();
|
||||
for( int j = 0; j < multi; j ++){
|
||||
bd[j] = mb->events[i][j].bd;
|
||||
|
|
173
MultiBuilder.cpp
173
MultiBuilder.cpp
|
@ -2,21 +2,57 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
MultiBuilder::MultiBuilder(Digitizer ** digi, unsigned int nDigi) : nData(nDigi){
|
||||
|
||||
MultiBuilder::MultiBuilder(Digitizer ** digi, unsigned int nDigi) : nData(nDigi){
|
||||
data = new Data *[nData];
|
||||
for( unsigned int i = 0; i < nData; i++){
|
||||
data[i] = digi[i]->GetData();
|
||||
typeList.push_back(digi[i]->GetDPPType());
|
||||
snList.push_back(digi[i]->GetSerialNumber());
|
||||
idList.push_back(i);
|
||||
timeWindow = 100;
|
||||
ClearEvents();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MultiBuilder::MultiBuilder(Data ** inData, std::vector<int> type) : nData(type.size()){
|
||||
MultiBuilder::MultiBuilder(Digitizer ** digi, std::vector<int> id) : nData(id.size()){
|
||||
data = new Data *[nData];
|
||||
idList = id;
|
||||
for( unsigned int i = 0; i < nData; i++){
|
||||
int k = idList[i];
|
||||
data[i] = digi[k]->GetData();
|
||||
typeList.push_back(digi[k]->GetDPPType());
|
||||
snList.push_back(digi[k]->GetSerialNumber());
|
||||
timeWindow = 100;
|
||||
ClearEvents();
|
||||
}
|
||||
}
|
||||
|
||||
MultiBuilder::MultiBuilder(Data ** inData, std::vector<int> type, std::vector<int> sn) : nData(type.size()){
|
||||
data = inData;
|
||||
typeList = type;
|
||||
snList = sn;
|
||||
for( int i = 0; i < (int) type.size(); i++) idList.push_back(i);
|
||||
timeWindow = 100;
|
||||
ClearEvents();
|
||||
}
|
||||
|
||||
MultiBuilder::MultiBuilder(Digitizer ** digi, int digiID) : nData(1){
|
||||
data = new Data *[nData];
|
||||
data[0] = digi[digiID]->GetData();
|
||||
typeList.push_back(digi[digiID]->GetDPPType());
|
||||
snList.push_back(digi[digiID]->GetSerialNumber());
|
||||
idList.push_back(digiID);
|
||||
timeWindow = 100;
|
||||
ClearEvents();
|
||||
}
|
||||
|
||||
MultiBuilder::MultiBuilder(Digitizer * digi) : nData(1){
|
||||
data = new Data *[1];
|
||||
data[0] = digi->GetData();
|
||||
typeList.push_back(digi->GetDPPType());
|
||||
snList.push_back(digi->GetSerialNumber());
|
||||
idList.push_back(0);
|
||||
timeWindow = 100;
|
||||
ClearEvents();
|
||||
}
|
||||
|
@ -83,10 +119,46 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
|
|||
|
||||
}
|
||||
|
||||
void MultiBuilder::FindLatestTime(bool verbose){
|
||||
void MultiBuilder::FindLatestTimeAndCh(bool verbose){
|
||||
|
||||
latestTime = 0;
|
||||
int latestCh = -1;
|
||||
int latestDigi = -1;
|
||||
latestDigi = -1;
|
||||
latestCh = -1;
|
||||
|
||||
nExhaushedCh = 0;
|
||||
|
||||
for( int i = 0; i < nData; i++){
|
||||
|
||||
for( int j = 0; j < MaxNChannels; j++ ){
|
||||
chExhaused[i][j] = false;
|
||||
}
|
||||
|
||||
for(unsigned int ch = 0; ch < MaxNChannels; ch ++){
|
||||
if( data[i]->Timestamp[ch][data[i]->DataIndex[ch]] == 0 || data[i]->DataIndex[ch] == -1 ) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[i][ch] = true;
|
||||
continue;
|
||||
}else{
|
||||
nextIndex[i][ch] = data[i]->DataIndex[ch];
|
||||
}
|
||||
|
||||
unsigned long long time = data[i]->Timestamp[ch][nextIndex[i][ch]];
|
||||
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){
|
||||
latestTime = 0;
|
||||
latestCh = -1;
|
||||
latestDigi = -1;
|
||||
for( int i = 0; i < nData; i++){
|
||||
for( unsigned ch = 0; ch < MaxNChannels; ch++ ){
|
||||
int index = data[i]->DataIndex[ch];
|
||||
|
@ -103,7 +175,7 @@ void MultiBuilder::FindLatestTime(bool verbose){
|
|||
|
||||
void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
||||
|
||||
FindLatestTime(verbose);
|
||||
FindLatestTimeOfData(verbose);
|
||||
|
||||
FindEarlistTimeAndCh(verbose);
|
||||
if( earlistCh == -1 || nExhaushedCh == nData * MaxNChannels) return; /// no data
|
||||
|
@ -137,7 +209,8 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
unsigned long long time = data[k]->Timestamp[ch][nextIndex[k][ch]];
|
||||
|
||||
if( time >= earlistTime && (time - earlistTime <= timeWindow) ){
|
||||
em.bd = k; // TODO serial number
|
||||
em.sn = snList[k];
|
||||
em.bd = k;
|
||||
em.ch = ch;
|
||||
em.energy = data[k]->Energy[ch][nextIndex[k][ch]];
|
||||
em.timestamp = time;
|
||||
|
@ -194,3 +267,87 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
}while(nExhaushedCh < nData * MaxNChannels);
|
||||
|
||||
}
|
||||
|
||||
void MultiBuilder::BuildEventsBackWard(bool verbose){
|
||||
|
||||
//skip trace, and only build for 100 events max
|
||||
|
||||
FindLatestTimeAndCh(verbose);
|
||||
|
||||
//========== build event
|
||||
eventBuilt = 0;
|
||||
EventMember em;
|
||||
do{
|
||||
eventIndex ++;
|
||||
if( eventIndex >= MaxNEvent ) eventIndex = 0;
|
||||
events[eventIndex].clear();
|
||||
|
||||
eventBuilt ++;
|
||||
totalEventBuilt ++;
|
||||
em.Clear();
|
||||
|
||||
for( int k = 0; k < nData; k++){
|
||||
for( unsigned int i = 0; i < MaxNChannels; i++){
|
||||
int ch = (i + latestCh) % MaxNChannels;
|
||||
if( chExhaused[k][ch] ) continue;
|
||||
if( nextIndex[k][ch] <= lastBackWardIndex[k][ch] ){
|
||||
chExhaused[k][ch] = true;
|
||||
nExhaushedCh ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
do{
|
||||
|
||||
unsigned long long time = data[k]->Timestamp[ch][nextIndex[k][ch]];
|
||||
if( time <= latestTime && (latestTime - time <= timeWindow)){
|
||||
em.sn = snList[k];
|
||||
em.bd = k;
|
||||
em.ch = ch;
|
||||
em.energy = data[k]->Energy[ch][nextIndex[k][ch]];
|
||||
em.timestamp = time;
|
||||
if( typeList[k] == V1730_DPP_PSD_CODE ) em.energy2 = data[k]->Energy2[ch][nextIndex[k][ch]];
|
||||
|
||||
events[eventIndex].push_back(em);
|
||||
nextIndex[k][ch]--;
|
||||
if( nextIndex[k][ch] < 0) nextIndex[k][ch] = MaxNData - 1;
|
||||
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
if( timeWindow == 0 ) break;
|
||||
}while(true);
|
||||
if( timeWindow == 0 ) break;
|
||||
}
|
||||
if( timeWindow == 0 ) break;
|
||||
}
|
||||
|
||||
//skip sorting by timestamp
|
||||
|
||||
FindLatestTimeAndCh(verbose);
|
||||
|
||||
if( verbose ){
|
||||
printf(">>>>>>>>>>>>>>>>> Event ID : %ld, total built: %ld, multiplicity : %ld\n", eventIndex, totalEventBuilt, events[eventIndex].size());
|
||||
for( int i = 0; i <(int) events[eventIndex].size(); i++){
|
||||
int chxxx = events[eventIndex][i].ch;
|
||||
int bd = events[eventIndex][i].bd;
|
||||
printf("%02d, %02d | %d | %5d %llu \n", bd, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp);
|
||||
}
|
||||
|
||||
if( nExhaushedCh == nData * MaxNChannels ) {
|
||||
printf("######################### no more event to be built\n");
|
||||
break;
|
||||
}
|
||||
printf("----- next ch : %d, next earlist Time : %llu.\n", earlistCh, earlistTime);
|
||||
|
||||
}
|
||||
|
||||
}while(nExhaushedCh < nData * MaxNChannels || eventBuilt > 100);
|
||||
|
||||
// remember the end of DataIndex, prevent over build
|
||||
for( int k = 0; k < nData; k++){
|
||||
for( int i = 0; i < MaxNChannels; i++){
|
||||
lastBackWardIndex[k][i] = data[k]->DataIndex[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
class EventMember{
|
||||
public:
|
||||
int sn;
|
||||
unsigned short bd;
|
||||
unsigned short ch;
|
||||
unsigned short energy;
|
||||
|
@ -21,18 +22,8 @@ public:
|
|||
Clear();
|
||||
}
|
||||
|
||||
// EventMember operator = (EventMember e){
|
||||
// bd = e.bd;
|
||||
// ch = e.ch;
|
||||
// energy = e.energy;
|
||||
// energy2 = e.energy2;
|
||||
// timestamp = e.timestamp;
|
||||
// fineTime = e.fineTime;
|
||||
// trace = e.trace;
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
void Clear(){
|
||||
sn = 0;
|
||||
bd = 0;
|
||||
ch = 0;
|
||||
energy = 0;
|
||||
|
@ -49,13 +40,22 @@ class MultiBuilder {
|
|||
|
||||
public:
|
||||
MultiBuilder(Digitizer ** digi, unsigned int nDigi);
|
||||
MultiBuilder(Data ** inData, std::vector<int> type);
|
||||
MultiBuilder(Digitizer ** digi, std::vector<int> id);
|
||||
MultiBuilder(Data ** inData, std::vector<int> type, std::vector<int> sn);
|
||||
|
||||
//for signal digitizer
|
||||
MultiBuilder(Digitizer ** digi, int digiID);
|
||||
MultiBuilder(Digitizer * digi);
|
||||
~MultiBuilder();
|
||||
|
||||
void SetTimeWindow(int ticks) {timeWindow = ticks;}
|
||||
int GetTimeWindow() const{return timeWindow;}
|
||||
|
||||
unsigned int GetNumOfDigitizer() const {return nData;}
|
||||
std::vector<int> GetDigiIDList() const {return idList;}
|
||||
|
||||
void BuildEvents(bool isFinal = false, bool skipTrace = false, bool verbose = false);
|
||||
void BuildEventsBackWard(bool verbose = false); // always skip trace, for faster online building
|
||||
|
||||
void ClearEvents();
|
||||
// void PrintStat();
|
||||
|
@ -67,6 +67,8 @@ public:
|
|||
|
||||
private:
|
||||
std::vector<int> typeList;
|
||||
std::vector<int> snList;
|
||||
std::vector<int> idList;
|
||||
const unsigned short nData;
|
||||
Data ** data; // assume all data has MaxNChannel (16)
|
||||
|
||||
|
@ -76,12 +78,19 @@ private:
|
|||
|
||||
int nExhaushedCh;
|
||||
bool chExhaused[MaxNDigitizer][MaxNChannels];
|
||||
|
||||
void FindEarlistTimeAndCh(bool verbose = false); // search thtough the nextIndex
|
||||
unsigned long long earlistTime;
|
||||
unsigned long long latestTime;
|
||||
int earlistDigi;
|
||||
int earlistCh;
|
||||
void FindEarlistTimeAndCh(bool verbose = false);
|
||||
void FindLatestTime(bool verbose = false);
|
||||
void FindLatestTimeAndCh(bool verbose = false); // search thtough the nextIndex
|
||||
unsigned long long latestTime;
|
||||
int latestDigi;
|
||||
int latestCh;
|
||||
|
||||
void FindLatestTimeOfData(bool verbose = false);
|
||||
|
||||
int lastBackWardIndex[MaxNDigitizer][MaxNChannels];
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ class SplitPole : public Analyzer{
|
|||
public:
|
||||
SplitPole(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
|
||||
|
||||
SetDigiID(0); // define which digitizer to build event
|
||||
SetUpdateTimeInSec(1.0);
|
||||
|
||||
RedefineEventBuilder({0}); // only build for the 0-th digitizer;
|
||||
evtbder = GetEventBuilder();
|
||||
|
||||
SetUpCanvas();
|
||||
|
|
Loading…
Reference in New Issue
Block a user