Compare commits

...

7 Commits

Author SHA1 Message Date
Calem@RAISOR b9158237e4 new screens in analyzers 2024-09-05 15:04:35 -05:00
Calem@RAISOR 55bbb5a7cb few FSUDAQ updates 2024-09-05 15:04:12 -05:00
Calem@RAISOR 60da1a4bd6 first set of commits 2024-09-05 15:03:31 -05:00
RAISOR Group 0ea74d8c70 snapshot 2024-06-07 11:34:59 -05:00
RAISOR Group cf2cf51095 Merge remote-tracking branch 'origin' into raisor 2024-06-04 12:00:14 -05:00
RAISOR Group f7b78a9f19 snapshot June-4 2024-06-04 11:59:18 -05:00
RAISOR Group c8d5d2d0c4 First save of working files specific to RAISOR 2024-05-17 10:11:36 -05:00
17 changed files with 2733 additions and 458 deletions

View File

@ -7,9 +7,10 @@
#include "TFile.h"
#include "TTree.h"
#include "TMacro.h"
#include "TMath.h"
#define MAX_MULTI 2000
#define MAX_TRACE_LENGTH 2000
#define MAX_MULTI 100
struct FileInfo{
@ -19,6 +20,9 @@ struct FileInfo{
};
#define NMINARG 5
#define debug 0
//^#############################################################
//^#############################################################
int main(int argc, char **argv) {
@ -26,16 +30,16 @@ int main(int argc, char **argv) {
printf("=========================================\n");
printf("=== *.fsu Events Builder ===\n");
printf("=========================================\n");
if (argc < 6) {
if (argc < NMINARG) {
printf("Incorrect number of arguments:\n");
printf("%s [timeWindow] [withTrace] [verbose] [batchSize] [inFile1] [inFile2] .... \n", argv[0]);
printf("%s [timeWindow] [withTrace] [format] [inFile1] [inFile2] .... \n", argv[0]);
printf(" timeWindow : in ns, -1 = no event building \n");
printf(" withTrace : 0 for no trace, 1 for trace \n");
printf(" verbose : > 0 for debug \n");
printf(" batchSize : the size of hit in a batch \n");
printf(" format : 0 for root, 1 for CoMPASS binary \n");
printf(" Output file name is contructed from inFile1 \n");
printf("\n");
printf(" Example: %s 0 0 0 10000 '\\ls -1 *001*.fsu'\n", argv[0]);
printf(" Example: %s -1 0 0 '\\ls -1 *001*.fsu' (no event build, no trace, no verbose)\n", argv[0]);
printf(" %s 100 0 0 '\\ls -1 *001*.fsu' (event build with 100 ns, no trace, no verbose)\n", argv[0]);
printf("\n\n");
return 1;
@ -46,11 +50,12 @@ int main(int argc, char **argv) {
///============= read input
long timeWindow = atoi(argv[1]);
bool traceOn = atoi(argv[2]);
unsigned int debug = atoi(argv[3]);
unsigned int batchSize = atoi(argv[4]);
int nFile = argc - 5;
// unsigned int debug = atoi(argv[3]);
unsigned short format = atoi(argv[3]);
unsigned int batchSize = 2* DEFAULT_HALFBUFFERSIZE;
int nFile = argc - NMINARG + 1;
TString inFileName[nFile];
for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i+5];}
for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i + NMINARG -1];}
/// Form outFileName;
TString outFileName = inFileName[0];
@ -59,17 +64,26 @@ int main(int argc, char **argv) {
pos = outFileName.Index("_", pos+1); // find next "_"
if( nFile == 1 ) pos = outFileName.Index("_", pos+1); // find next "_", S/N
outFileName.Remove(pos); // remove the rest
outFileName += "_" + std::to_string(timeWindow);
outFileName += ".root";
printf("-------> Out file name : %s \n", outFileName.Data());
outFileName += "_" + ( timeWindow >= 0 ? std::to_string(timeWindow) : "single");
TString outFileFullName;
if( format == 0 ){
outFileFullName = outFileName + ".root";
}else{
outFileFullName = outFileName + ".bin";
}
uint16_t header = 0; // for caen bin
printf("-------> Out file name : %s \n", outFileFullName.Data());
printf("========================================= Number of Files : %d \n", nFile);
for( int i = 0; i < nFile; i++) printf("%2d | %s \n", i, inFileName[i].Data());
printf("=========================================\n");
printf(" Time Window = %ld ns = %.1f us\n", timeWindow, timeWindow/1000.);
printf(" Include Trace = %s\n", traceOn ? "Yes" : "No");
printf(" Debug level = %d\n", debug);
printf(" Batch size = %d events/file\n", batchSize);
printf(" Max multiplity = %d hits/event (hard coded)\n", MAX_MULTI);
printf(" Time Window = %ld ns = %.1f us\n", timeWindow, timeWindow/1000.);
printf(" Include Trace = %s\n", traceOn ? "Yes" : "No");
printf(" Debug level = %d\n", debug);
printf(" Max multiplity = %d hits/event (hard coded)\n", MAX_MULTI);
if( traceOn ) printf(" Max Trace Length = %d (hard coded)\n", MAX_TRACE_LENGTH);
printf("========================================= Grouping files\n");
std::vector<std::vector<FileInfo>> fileGroupList; // fileName and ID = SN * 1000 + index
@ -79,15 +93,18 @@ int main(int argc, char **argv) {
FSUReader * readerA = new FSUReader(inFileName[0].Data(), 1, 1);
readerA->ScanNumBlock(0,0);
FileInfo fileInfo = {inFileName[0].Data(), readerA->GetSN() * 1000 + readerA->GetFileOrder(), readerA->GetHitCount()};
if( readerA->GetOptimumBatchSize() > batchSize ) batchSize = readerA->GetOptimumBatchSize();
FileInfo fileInfo = {inFileName[0].Data(), readerA->GetSN() * 1000 + readerA->GetFileOrder(), readerA->GetTotalHitCount()};
fileList.push_back(fileInfo);
totalHitCount += readerA->GetHitCount();
totalHitCount += readerA->GetTotalHitCount();
for( int i = 1; i < nFile; i++){
FSUReader * readerB = new FSUReader(inFileName[i].Data(), 1, 0);
FSUReader * readerB = new FSUReader(inFileName[i].Data(), 1, 1);
readerB->ScanNumBlock(0,0);
totalHitCount += readerB->GetHitCount();
fileInfo = {inFileName[i].Data(), readerB->GetSN() * 1000 + readerB->GetFileOrder(), readerB->GetHitCount()};
if( readerB->GetOptimumBatchSize() > batchSize ) batchSize = readerB->GetOptimumBatchSize();
totalHitCount += readerB->GetTotalHitCount();
fileInfo = {inFileName[i].Data(), readerB->GetSN() * 1000 + readerB->GetFileOrder(), readerB->GetTotalHitCount()};
if( readerA->GetSN() == readerB->GetSN() ){
fileList.push_back(fileInfo);
@ -104,25 +121,21 @@ int main(int argc, char **argv) {
delete readerA;
printf("======================= total Hit Count : %llu\n", totalHitCount);
printf(">>>>>>>>>>>>>>>>>>>>>>>>>> Batch size : %d events/file\n", batchSize);
for( size_t i = 0; i < fileGroupList.size(); i++){
printf("group ----- %ld \n", i);
//sort by ID
std::sort(fileGroupList[i].begin(), fileGroupList[i].end(), [](const FileInfo & a, const FileInfo & b) {
return a.fileID < b.fileID;
});
for( size_t j = 0; j < fileGroupList[i].size(); j++){
printf("%3ld | %8d | %9lu| %s \n", j, fileGroupList[i][j].fileID, fileGroupList[i][j].hitCount, fileGroupList[i][j].fileName.c_str() );
}
}
// //*====================================== create tree
TFile * outRootFile = new TFile(outFileName, "recreate");
TTree * tree = new TTree("tree", outFileName);
TFile * outRootFile = nullptr;
TTree * tree = nullptr;
unsigned long long evID = 0;
unsigned int multi = 0;
unsigned short sn[MAX_MULTI] = {0}; /// board SN
@ -132,24 +145,37 @@ int main(int argc, char **argv) {
unsigned long long e_t[MAX_MULTI] = {0}; /// timestamp 47 bit
unsigned short e_f[MAX_MULTI] = {0}; /// fine time 10 bit
unsigned short traceLength[MAX_MULTI];
short trace[MAX_MULTI][MAX_TRACE_LENGTH];
tree->Branch("evID", &evID, "event_ID/l");
tree->Branch("multi", &multi, "multi/i");
tree->Branch("sn", sn, "sn[multi]/s");
tree->Branch("ch", ch, "ch[multi]/s");
tree->Branch("e", e, "e[multi]/s");
tree->Branch("e2", e2, "e2[multi]/s");
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
tree->Branch("e_f", e_f, "e_fineTime[multi]/s");
tree->Branch("traceLength", traceLength, "traceLength[multi]/s");
FILE * caen = nullptr;
TClonesArray * arrayTrace = nullptr;
TGraph * trace = nullptr;
if( format == 0 ){
// //*====================================== create tree
outRootFile = new TFile(outFileFullName, "recreate");
tree = new TTree("tree", outFileFullName);
tree->Branch("evID", &evID, "event_ID/l");
tree->Branch("multi", &multi, "multi/i");
tree->Branch("sn", sn, "sn[multi]/s");
tree->Branch("ch", ch, "ch[multi]/s");
tree->Branch("e", e, "e[multi]/s");
tree->Branch("e2", e2, "e2[multi]/s");
tree->Branch("e_t", e_t, "e_t[multi]/l");
tree->Branch("e_f", e_f, "e_f[multi]/s");
tree->Branch("traceLength", traceLength, "traceLength[multi]/s");
if( traceOn ) {
tree->Branch("trace", trace,"trace[multi][MAX_TRACE_LENGTH]/S");
tree->GetBranch("trace")->SetCompressionSettings(205);
}
}else{
caen = fopen(outFileFullName.Data(), "wb");
if( caen == nullptr ){
perror("Failed to open file");
return -1;
}
if( traceOn ) {
arrayTrace = new TClonesArray("TGraph");
tree->Branch("trace", arrayTrace, 2560000);
arrayTrace->BypassStreamer();
}
//*======================================= Open files
@ -165,9 +191,9 @@ int main(int argc, char **argv) {
for( size_t j = 0; j < fileGroupList[i].size(); j++){
fList.push_back( fileGroupList[i][j].fileName );
}
reader[i] = new FSUReader(fList, 600, debug);
reader[i] = new FSUReader(fList, 1024, debug); // 1024 is the maximum event / agg.
hitList[i] = reader[i]->ReadBatch(batchSize, debug );
reader[i]->PrintHitListInfo(hitList[i], "hitList-" + std::to_string(reader[i]->GetSN()));
reader[i]->PrintHitListInfo(&hitList[i], "hitList-" + std::to_string(reader[i]->GetSN()));
ID[i] = 0;
if( debug ) {
@ -216,6 +242,7 @@ int main(int argc, char **argv) {
//chekc if reached the end of hitList
if( ID[ig] >= hitList[ig].size() ) {
hitList[ig] = reader[ig]->ReadBatch(batchSize, debug + 1);
if( debug ) reader[ig]->PrintHitListInfo( &hitList[ig], "hitList-" + std::to_string(ig));
ID[ig] = 0;
if( hitList[ig].size() == 0 ) continue;
}
@ -234,6 +261,7 @@ int main(int argc, char **argv) {
//check if reached the end of hitList
if( ID[ig] >= hitList[ig].size() ) {
hitList[ig] = reader[ig]->ReadBatch(batchSize, debug);
if( debug ) reader[ig]->PrintHitListInfo( &hitList[ig], "hitList-" + std::to_string(ig));
ID[ig] = 0;
if( hitList[ig].size() == 0 ) break;
}
@ -258,15 +286,15 @@ int main(int argc, char **argv) {
tEnd = events.back().timestamp;
hitProcessed += events.size();
if( hitProcessed % 10000 == 0 ) printf("hit Porcessed %llu/%llu hit....%.2f%%\n\033[A\r", hitProcessed, totalHitCount, hitProcessed*100./totalHitCount);
if( hitProcessed % (traceOn ? 10000 : 10000) == 0 ) printf("hit Porcessed %llu/%llu hit....%.2f%%\n\033[A\r", hitProcessed, totalHitCount, hitProcessed*100./totalHitCount);
multi = events.size() ;
if( events.size() >= MAX_MULTI ) {
printf("event %lld has size = %d > MAX_MULTI = %d\n", evID, multi, MAX_MULTI);
printf("\033[31m event %lld has size = %d > MAX_MULTI = %d \033[0m\n", evID, multi, MAX_MULTI);
multi = MAX_MULTI;
}
if( debug ) printf("=================================== filling data | %u \n", multi);
for( size_t p = 0; p < multi ; p ++ ) {
if( debug ) {printf("%4zu | ", p); events[p].Print();}
@ -279,17 +307,38 @@ int main(int argc, char **argv) {
traceLength[p] = events[p].traceLength;
if( traceOn ){
trace = (TGraph *) arrayTrace->ConstructedAt(multi, "C");
trace->Clear();
for( int hh = 0; hh < traceLength[multi]; hh++){
trace->SetPoint(hh, hh, events[p].trace[hh]);
if( traceLength[p] > MAX_TRACE_LENGTH ) {
printf("\033[31m event %lld has trace length = %d > MAX_TRACE_LENGTH = %d \033[0m\n", evID, traceLength[p], MAX_TRACE_LENGTH);
traceLength[p] = MAX_TRACE_LENGTH;
}
for( int hh = 0; hh < traceLength[p]; hh++){
trace[p][hh] = events[p].trace[hh];
}
}
}
if( format == 0 ){
outRootFile->cd();
tree->Fill();
// tree->Write();
}else{
if( caen ) {
if( header == 0 ){
header = 0xCAE1; // default to have the energy only
if( events[0].energy2 > 0 ) header += 0x4;
if( events[0].traceLength > 0 && traceOn ) header += 0x8;
size_t dummy = fwrite(&header, 2, 1, caen);
if( dummy != 1 ) printf("file write error.\n");
}
for( size_t gg = 0; gg < events.size(); gg++ ){
events[gg].WriteHitsToCAENBinary(caen, header);
}
}
}
outRootFile->cd();
tree->Fill();
// tree->Write();
multi = 0;
evID ++;
@ -324,29 +373,35 @@ int main(int argc, char **argv) {
}while( nFileFinished < nGroup);
tree->Write();
if( format == 0 ) tree->Write();
uInt runEndTime = getTime_us();
double runTime = (runEndTime - runStartTime) * 1e-6;
printf("========================================= finished.\n");
printf(" event building time = %.2f sec = %.2f min\n", runTime, runTime/60.);
printf(" total events built = %llu by event builder (%llu in tree)\n", evID, tree->GetEntriesFast());
// printf(" total events built = %llu by event builder (%llu in tree)\n", evID, tree->GetEntriesFast());
printf(" total events built = %llu by event builder\n", evID);
double tDuration_sec = (tEnd - tStart) * 1e-9;
printf(" first timestamp = %20llu ns\n", tStart);
printf(" last timestamp = %20llu ns\n", tEnd);
printf(" total data duration = %.2f sec = %.2f min\n", tDuration_sec, tDuration_sec/60.);
printf("==============> saved to %s \n", outFileName.Data());
printf("========================================> saved to %s \n", outFileFullName.Data());
TMacro info;
info.AddLine(Form("tStart= %20llu ns",tStart));
info.AddLine(Form(" tEnd= %20llu ns",tEnd));
info.Write("info");
outRootFile->Close();
if( format == 0 ){
TMacro info;
info.AddLine(Form("tStart= %20llu ns",tStart));
info.AddLine(Form(" tEnd= %20llu ns",tEnd));
info.Write("info");
outRootFile->Close();
}else{
fclose(caen);
}
for( int i = 0; i < nGroup; i++) delete reader[i];
delete [] reader;
printf("####################################### end of %s\n", argv[0]);
return 0;
}

View File

@ -3,7 +3,7 @@
#include <algorithm>
#include <filesystem>
// #include "AggSeparator.h"
#define DEFAULT_HALFBUFFERSIZE 500000
class FSUReader{
@ -60,32 +60,25 @@ class FSUReader{
return hit[id];
}
void ClearHitCount() {hitCount = 0;}
ulong GetHitCount() const{return hitCount;}
void ClearTotalHitCount() {totalHitCount = 0;}
ulong GetTotalHitCount() const{return totalHitCount;}
std::vector<Hit> ReadBatch(unsigned int batchSize = 1000000, bool verbose = false); // output the sorted Hit
// std::string SaveHit(std::vector<Hit> hitList, bool isAppend = false);
// std::string SaveHit2NewFile(std::string saveFolder = "./", std::string indexStr = "");
// void SortAndSaveTS(unsigned int batchSize = 1000000, bool verbose = false);
// off_t GetTSFileSize() const {return tsFileSize;}
//TODO
//void SplitFile(unsigned long hitSizePreFile);
void PrintHit(ulong numHit = -1, ulong startIndex = 0) {
for( ulong i = startIndex; i < std::min(numHit, hitCount); i++){
for( ulong i = startIndex; i < std::min(numHit, totalHitCount); i++){
printf("%10zu ", i); hit[i].Print();
}
}
static void PrintHitListInfo(std::vector<Hit> hitList, std::string name){
size_t n = hitList.size();
static void PrintHitListInfo(std::vector<Hit> * hitList, std::string name){
size_t n = hitList->size();
size_t s = sizeof(Hit);
printf("============== %s, size : %zu | %.2f MByte\n", name.c_str(), n, n*s/1024./1024.);
if( n > 0 ){
printf("t0 : %15llu \n", hitList.at(0).timestamp);
printf("t1 : %15llu \n", hitList.back().timestamp);
printf("t0 : %15llu ns\n", hitList->front().timestamp);
printf("t1 : %15llu ns\n", hitList->back().timestamp);
printf("dt : %15.3f ms\n", (hitList->back().timestamp - hitList->front().timestamp)/1e6);
}
}
@ -94,13 +87,13 @@ class FSUReader{
size_t s = sizeof(Hit);
printf("============== reader.hit, size : %zu | %.2f MByte\n", n, n*s/1024./1024.);
if( n > 0 ){
printf("t0 : %15llu \n", hit.at(0).timestamp);
printf("t1 : %15llu \n", hit.back().timestamp);
printf("t0 : %15llu ns\n", hit.at(0).timestamp);
printf("t1 : %15llu ns\n", hit.back().timestamp);
printf("dt : %15.3f ms\n", (hit.back().timestamp - hit.front().timestamp)/1e6);
}
}
//void SaveAsCAENCoMPASSFormat();
unsigned long GetOptimumBatchSize() const {return optBufferSize;}
private:
@ -127,7 +120,7 @@ class FSUReader{
std::vector<unsigned int> blockPos;
std::vector<unsigned int > blockTimeStamp;
unsigned long hitCount;
unsigned long totalHitCount;
std::vector<Hit> hit;
@ -137,8 +130,15 @@ class FSUReader{
off_t tsFileSize;
//checking the t0 and tmin for every 1 million hit
unsigned short nMillion;
std::vector<unsigned long> tmin;
unsigned long optBufferSize;
};
//^==============================================================
inline FSUReader::~FSUReader(){
delete data;
@ -146,6 +146,7 @@ inline FSUReader::~FSUReader(){
}
//^==============================================================
inline FSUReader::FSUReader(){
inFile = nullptr;
data = nullptr;
@ -159,6 +160,7 @@ inline FSUReader::FSUReader(){
}
//^==============================================================
inline FSUReader::FSUReader(std::string fileName, uInt dataSize, int verbose){
inFile = nullptr;
data = nullptr;
@ -172,6 +174,7 @@ inline FSUReader::FSUReader(std::string fileName, uInt dataSize, int verbose){
OpenFile(fileName, dataSize, verbose);
}
//^==============================================================
inline FSUReader::FSUReader(std::vector<std::string> fileList, uInt dataSize, int verbose){
inFile = nullptr;
data = nullptr;
@ -186,6 +189,7 @@ inline FSUReader::FSUReader(std::vector<std::string> fileList, uInt dataSize, in
}
//^==============================================================
inline void FSUReader::OpenFile(std::string fileName, uInt dataSize, int verbose){
/// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu
@ -221,9 +225,14 @@ inline void FSUReader::OpenFile(std::string fileName, uInt dataSize, int verbose
blockPos.clear();
blockTimeStamp.clear();
hitCount = 0;
totalHitCount = 0;
hit.clear();
nMillion = 0;
tmin.clear();
tmin.push_back(-1);
optBufferSize = 2*DEFAULT_HALFBUFFERSIZE;
//check is the file is *.fsu or *.fsu.X
size_t found = fileName.find_last_of('.');
std::string ext = fileName.substr(found + 1);
@ -277,6 +286,7 @@ inline void FSUReader::OpenFile(std::string fileName, uInt dataSize, int verbose
}
//^==============================================================
inline int FSUReader::ReadNextBlock(bool traceON, int verbose, uShort saveData){
if( inFile == NULL ) return -1;
if( feof(inFile) || filePos >= inFileSize) {
@ -332,13 +342,22 @@ inline int FSUReader::ReadNextBlock(bool traceON, int verbose, uShort saveData){
return -20;
}
unsigned int eventCout = 0;
for( int ch = 0; ch < data->GetNChannel(); ch++){
if( data->NumEventsDecoded[ch] == 0 ) continue;
hitCount += data->NumEventsDecoded[ch];
eventCout += data->NumEventsDecoded[ch];
totalHitCount += data->NumEventsDecoded[ch];
if( totalHitCount / DEFAULT_HALFBUFFERSIZE > nMillion ) {
nMillion ++;
tmin.push_back(-1);
}
int start = data->GetDataIndex(ch) - data->NumEventsDecoded[ch] + 1;
if( start < 0 ) start = start + data->GetDataSize();
for( int i = start; i < start + data->NumEventsDecoded[ch]; i++ ){
int k = i % data->GetDataSize();
if( data->GetTimestamp(ch, k) < tmin[nMillion] ) tmin[nMillion] = data->GetTimestamp(ch, k);
}
if( saveData ){
int start = data->GetDataIndex(ch) - data->NumEventsDecoded[ch] + 1;
@ -373,6 +392,7 @@ inline int FSUReader::ReadNextBlock(bool traceON, int verbose, uShort saveData){
return 0;
}
//^==============================================================
inline int FSUReader::ReadBlock(unsigned int ID, int verbose){
if( totNumBlock == 0 )return -1;
if( ID >= totNumBlock )return -1;
@ -390,6 +410,7 @@ inline int FSUReader::ReadBlock(unsigned int ID, int verbose){
}
//^==============================================================
inline void FSUReader::SortHit(int verbose){
if( verbose) printf("\nQuick Sort hit array according to time...");
std::sort(hit.begin(), hit.end(), [](const Hit& a, const Hit& b) {
@ -398,6 +419,7 @@ inline void FSUReader::SortHit(int verbose){
if( verbose) printf(".......done.\n");
}
//^==============================================================
inline void FSUReader::ScanNumBlock(int verbose, uShort saveData){
if( inFile == nullptr ) return;
if( feof(inFile) ) return;
@ -421,8 +443,8 @@ inline void FSUReader::ScanNumBlock(int verbose, uShort saveData){
totNumBlock = blockID;
if(verbose) {
printf("\nScan complete: number of data Block : %lu\n", totNumBlock);
printf( " number of hit : %lu", hitCount);
if( hitCount > 1e6 ) printf(" = %.3f million", hitCount/1e6);
printf( " number of hit : %lu", totalHitCount);
if( totalHitCount > 1e6 ) printf(" = %.3f million", totalHitCount/1e6);
printf("\n");
if( saveData )printf( " size of the hit array : %lu\n", hit.size());
@ -443,14 +465,32 @@ inline void FSUReader::ScanNumBlock(int verbose, uShort saveData){
//check is the hitCount == hit.size();
if( saveData ){
if( hitCount != hit.size()){
if( totalHitCount != hit.size()){
printf("!!!!!! the Data::dataSize is not big enough. !!!!!!!!!!!!!!!\n");
}else{
SortHit(verbose+1);
}
}
//print time structre
if( nMillion > 0 ){
// printf("------------ time structure\n");
// printf("%5s | %15s\n", "mil.", "t-min");
for( int i = 0; i < nMillion; i++){
// printf("%5d | %15lu", i, tmin[i]);
if( i > 0 && tmin[i] < tmin[i-1] ) {
// printf("<----");
if( i > 1 && tmin[i] < tmin[i-2]) optBufferSize += 2*DEFAULT_HALFBUFFERSIZE;
}
// printf("\n");
}
}
// printf(" recommanded batch size : %lu\n", optBufferSize);
}
//^==============================================================
inline std::vector<Hit> FSUReader::ReadBatch(unsigned int batchSize, bool verbose){
// printf("%s sn:%d. filePos : %lu\n", __func__, sn, ftell(inFile));
@ -472,8 +512,9 @@ inline std::vector<Hit> FSUReader::ReadBatch(unsigned int batchSize, bool verbos
uLong t1_B = hit.back().timestamp;
if( verbose ) {
printf(" hit in memeory : %7zu | %u | %lu \n", hit.size(), filePos, inFileSize);
printf("t0 : %15lu\n", t0_B);
printf("t1 : %15lu\n", t1_B);
printf("t0 : %15lu ns\n", t0_B);
printf("t1 : %15lu ns\n", t1_B);
printf("dt : %15.3f ms\n", (t1_B - t0_B)/1e6);
}
hitList_A = hit;
@ -500,6 +541,7 @@ inline std::vector<Hit> FSUReader::ReadBatch(unsigned int batchSize, bool verbos
printf(" hit in memeory : %7zu | %u | %lu \n", hit.size(), filePos, inFileSize);
printf("t0 : %15lu\n", t0_B);
printf("t1 : %15lu\n", t1_B);
printf("dt : %15.3f ms\n", (t1_B - t0_B)/1e6);
}
uLong t0_A = hitList_A.at(0).timestamp;
@ -509,6 +551,8 @@ inline std::vector<Hit> FSUReader::ReadBatch(unsigned int batchSize, bool verbos
if( t0_A >= t0_B) {
printf("\033[0;31m!!!!!!!!!!!!!!!!! %s | Need to increase the batch size. \033[0m\n", __func__);
printf("t0_A : %15lu\n", t0_A);
printf("t0_B : %15lu\n", t0_B);
return std::vector<Hit> ();
}
@ -552,8 +596,8 @@ inline std::vector<Hit> FSUReader::ReadBatch(unsigned int batchSize, bool verbos
if( verbose ) {
printf("----------------- ID_A : %lu, Drop\n", ID_A);
printf("----------------- ID_B : %lu, Drop\n", ID_B);
PrintHitListInfo(hitList_A, "hitList_A");
PrintHitListInfo(hitTemp, "hitTemp");
PrintHitListInfo(&hitList_A, "hitList_A");
PrintHitListInfo(&hitTemp, "hitTemp");
PrintHitListInfo();
printf("=========== sume of A + B + Temp : %zu \n", hitList_A.size() + hit.size() + hitTemp.size());
printf("----------------- refill hitList_A \n");
@ -565,7 +609,7 @@ inline std::vector<Hit> FSUReader::ReadBatch(unsigned int batchSize, bool verbos
hitTemp.clear();
if( verbose ) {
PrintHitListInfo(hitList_A, "hitList_A");
PrintHitListInfo(&hitList_A, "hitList_A");
PrintHitListInfo();
printf("=========== sume of A + B : %zu \n", hitList_A.size() + hit.size());
}
@ -576,216 +620,3 @@ inline std::vector<Hit> FSUReader::ReadBatch(unsigned int batchSize, bool verbos
}
/*
inline void FSUReader::SortAndSaveTS(unsigned int batchSize, bool verbose){
int count = 0;
std::vector<Hit> hitList_A ;
do{
if( verbose ) printf("***************************************************\n");
int res = 0;
do{
res = ReadNextBlock(true, 0, 3);
}while ( hit.size() < batchSize && res == 0);
SortHit();
uLong t0_B = hit.at(0).timestamp;
uLong t1_B = hit.back().timestamp;
if( verbose ) {
printf(" hit in memeory : %7zu | %u | %lu \n", hit.size(), filePos, inFileSize);
printf("t0 : %15lu\n", t0_B);
printf("t1 : %15lu\n", t1_B);
}
if( count == 0 ) {
hitList_A = hit; // copy hit
}else{
uLong t0_A = hitList_A.at(0).timestamp;
uLong t1_A = hitList_A.back().timestamp;
ulong ID_A = 0;
ulong ID_B = 0;
if( t0_A > t0_B) {
printf("Need to increase the batch size. \n");
return;
}
if( t1_A > t0_B) { // need to sort between two hitList
if( verbose ) {
printf("############# need to sort \n");
printf("=========== sume of A + B : %zu \n", hitList_A.size() + hit.size());
}
std::vector<Hit> hitTemp;
for( size_t j = 0; j < hitList_A.size() ; j++){
if( hitList_A[j].timestamp < t0_B ) continue;
if( ID_A == 0 ) ID_A = j;
hitTemp.push_back(hitList_A[j]);
}
hitList_A.erase(hitList_A.begin() + ID_A, hitList_A.end() );
if( verbose ) {
printf("----------------- ID_A : %lu, Drop\n", ID_A);
PrintHitListInfo(hitList_A, "hitList_A");
}
for( size_t j = 0; j < hit.size(); j++){
if( hit[j].timestamp > t1_A ) {
ID_B = j;
break;
}
hitTemp.push_back(hit[j]);
}
std::sort(hitTemp.begin(), hitTemp.end(), [](const Hit& a, const Hit& b) {
return a.timestamp < b.timestamp;
});
hit.erase(hit.begin(), hit.begin() + ID_B );
if( verbose ) {
PrintHitListInfo(hitTemp, "hitTemp");
printf("----------------- ID_B : %lu, Drop\n", ID_B);
PrintHitListInfo(hit, "hit");
printf("=========== sume of A + B + Temp : %zu \n", hitList_A.size() + hit.size() + hitTemp.size());
printf("----------------- refill hitList_A \n");
}
ulong ID_Temp = 0;
for( size_t j = 0; j < hitTemp.size(); j++){
hitList_A.push_back(hitTemp[j]);
if( hitList_A.size() >= batchSize ) {
ID_Temp = j+1;
break;
}
}
hitTemp.erase(hitTemp.begin(), hitTemp.begin() + ID_Temp );
for( size_t j = 0 ; j < hit.size(); j ++){
hitTemp.push_back(hit[j]);
}
SaveHit(hitList_A, count <= 1 ? false : true);
if( verbose ) {
PrintHitListInfo(hitList_A, "hitList_A");
PrintHitListInfo(hitTemp, "hitTemp");
printf("----------------- replace hitList_A by hitTemp \n");
}
hitList_A.clear();
hitList_A = hitTemp;
hit.clear();
if( verbose ) {
PrintHitListInfo(hitList_A, "hitList_A");
printf("===========================================\n");
}
}else{ // save hitList_A, replace hitList_A
SaveHit(hitList_A, count <= 1? false : true);
hitList_A.clear();
hitList_A = hit;
if( verbose ) PrintHitListInfo(hitList_A, "hitList_A");
}
}
ClearHitList();
count ++;
}while(filePos < inFileSize);
SaveHit(hitList_A, count <= 1 ? false : true);
printf("================= finished.\n");
}
*/
/*
inline std::string FSUReader::SaveHit(std::vector<Hit> hitList, bool isAppend){
std::string outFileName;
if( fileList.empty() ) {
outFileName = fileName + ".ts" ;
}else{
outFileName = fileList[0] + ".ts" ;
}
uint64_t hitSize = hitList.size();
FILE * outFile ;
if( isAppend ) {
outFile = fopen(outFileName.c_str(), "rb+"); //read/write bineary
rewind(outFile);
fseek( outFile, 4, SEEK_CUR);
uint64_t org_hitSize;
fread(&org_hitSize, 8, 1, outFile);
rewind(outFile);
fseek( outFile, 4, SEEK_CUR);
org_hitSize += hitSize;
fwrite(&org_hitSize, 8, 1, outFile);
fseek(outFile, 0, SEEK_END);
}else{
outFile = fopen(outFileName.c_str(), "wb"); //overwrite binary
uint32_t header = 0xAA000000;
header += sn;
fwrite( &header, 4, 1, outFile );
fwrite( &hitSize, 8, 1, outFile);
}
for( ulong i = 0; i < hitSize; i++){
if( i% 10000 == 0 ) printf("Saving %lu/%lu Hit (%.2f%%)\n\033[A\r", i, hitSize, i*100./hitSize);
uint16_t flag = hitList[i].ch + (hitList[i].pileUp << 8) ;
if( DPPType == DPPTypeCode::DPP_PSD_CODE ) flag += ( 1 << 15);
if( hitList[i].traceLength > 0 ) flag += (1 << 14);
// fwrite( &(hit[i].ch), 1, 1, outFile);
fwrite( &flag, 2, 1, outFile);
fwrite( &(hitList[i].energy), 2, 1, outFile);
if( DPPType == DPPTypeCode::DPP_PSD_CODE ) fwrite( &(hitList[i].energy2), 2, 1, outFile);
fwrite( &(hitList[i].timestamp), 6, 1, outFile);
fwrite( &(hitList[i].fineTime), 2, 1, outFile);
if( hitList[i].traceLength > 0 ) fwrite( &(hitList[i].traceLength), 2, 1, outFile);
for( uShort j = 0; j < hitList[i].traceLength; j++){
fwrite( &(hitList[i].trace[j]), 2, 1, outFile);
}
}
off_t tsFileSize = ftello(outFile); // unsigned int = Max ~4GB
fclose(outFile);
printf("Saved to %s, size: ", outFileName.c_str());
if( tsFileSize < 1024 ) {
printf(" %ld Byte", tsFileSize);
}else if( tsFileSize < 1024*1024 ) {
printf(" %.2f kB", tsFileSize/1024.);
}else if( tsFileSize < 1024*1024*1024){
printf(" %.2f MB", tsFileSize/1024./1024.);
}else{
printf(" %.2f GB", tsFileSize/1024./1024./1024.);
}
printf("\n");
return outFileName;
}
*/

View File

@ -18,9 +18,18 @@
#include "analyzers/CoincidentAnalyzer.h"
#include "analyzers/SplitPoleAnalyzer.h"
#include "analyzers/EncoreAnalyzer.h"
#include "analyzers/RAISOR.h"
#include "analyzers/RAISOR1.h"
#include "analyzers/RAISOR2.h"
#include "analyzers/TEST.h"
#include "analyzers/MCP.h"
#include "analyzers/MCPandPSD.h"
#include "analyzers/PID.h"
#include "analyzers/Cross.h"
#include "analyzers/Target.h"
#include "analyzers/BeamTune.h"
std::vector<std::string> onlineAnalyzerList = {"Coincident","Splie-Pole", "Encore", "RAISOR"};
std::vector<std::string> onlineAnalyzerList = {"Coincident","Splie-Pole", "Encore", "RAISOR1", "MCP", "PID", "RAISOR2", "TEST", "MCPandPSD", "Cross", "Target", "BeamTune" };
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
DebugPrint("%s", "FSUDAQ");
@ -55,7 +64,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
cbOpenDigitizers = new RComboBox(this);
cbOpenDigitizers->addItem("Open Digitizers ... ", 0);
cbOpenDigitizers->addItem("Open Digitizers via Optical", 1);
cbOpenDigitizers->addItem("Open Digitizers via Optical/USB", 1);
// cbOpenDigitizers->addItem("Open Digitizers (default program)", 2);
// cbOpenDigitizers->addItem("Open Digitizers + load Settings", 3);
//cbOpenDigitizers->addItem("Open Digitizers via USB", 3);
@ -1813,7 +1822,15 @@ void MainWindow::OpenAnalyzer(){
if( id == 0 ) onlineAnalyzer = new CoincidentAnalyzer(digi, nDigi);
if( id == 1 ) onlineAnalyzer = new SplitPole(digi, nDigi);
if( id == 2 ) onlineAnalyzer = new Encore(digi, nDigi);
if( id == 3 ) onlineAnalyzer = new RAISOR(digi, nDigi);
if( id == 3 ) onlineAnalyzer = new RAISOR1(digi, nDigi);
if( id == 4 ) onlineAnalyzer = new MCP(digi, nDigi);
if( id == 5 ) onlineAnalyzer = new PID(digi, nDigi);
if( id == 6 ) onlineAnalyzer = new RAISOR2(digi, nDigi);
if( id == 7 ) onlineAnalyzer = new TEST(digi, nDigi);
if( id == 8 ) onlineAnalyzer = new MCPandPSD(digi, nDigi);
if( id == 9 ) onlineAnalyzer = new Cross(digi, nDigi);
if( id == 10 ) onlineAnalyzer = new Target(digi, nDigi);
if( id == 11 ) onlineAnalyzer = new BeamTune(digi, nDigi);
if( id >= 0 ) onlineAnalyzer->show();
}else{
@ -1822,8 +1839,15 @@ void MainWindow::OpenAnalyzer(){
if( id == 0 ) onlineAnalyzer = new CoincidentAnalyzer(digi, nDigi);
if( id == 1 ) onlineAnalyzer = new SplitPole(digi, nDigi);
if( id == 2 ) onlineAnalyzer = new Encore(digi, nDigi);
if( id == 3 ) onlineAnalyzer = new RAISOR(digi, nDigi);
if( id == 3 ) onlineAnalyzer = new RAISOR1(digi, nDigi);
if( id == 4 ) onlineAnalyzer = new MCP(digi, nDigi);
if( id == 5 ) onlineAnalyzer = new PID(digi, nDigi);
if( id == 6 ) onlineAnalyzer = new RAISOR2(digi, nDigi);
if( id == 7 ) onlineAnalyzer = new TEST(digi, nDigi);
if( id == 8 ) onlineAnalyzer = new MCPandPSD(digi, nDigi);
if( id == 9 ) onlineAnalyzer = new Cross(digi, nDigi);
if( id == 10 ) onlineAnalyzer = new Target(digi, nDigi);
if( id == 11 ) onlineAnalyzer = new BeamTune(digi, nDigi);
if( id >= 0 ){
onlineAnalyzer->show();
onlineAnalyzer->activateWindow();

View File

@ -44,7 +44,15 @@ HEADERS += ClassData.h \
analyzers/CoincidentAnalyzer.h \
analyzers/SplitPoleAnalyzer.h \
analyzers/EncoreAnalyzer.h \
analyzers/RAISOR.h
analyzers/RAISOR1.h \
analyzers/RAISOR2.h \
analyzers/TEST.h \
analyzers/MCPandPSD.h \
analyzers/MCP.h \
analyzers/Cross.h\
analyzers/Target.h\
analyzers/BeamTune.h\
analyzers/PID.h
SOURCES += ClassDigitizer.cpp \
DigiSettingsPanel.cpp \
FSUDAQ.cpp \

38
Hit.h
View File

@ -6,7 +6,7 @@
class Hit{
public:
unsigned short sn;
uint8_t ch;
unsigned short ch;
unsigned short energy;
unsigned short energy2;
unsigned long long timestamp;
@ -47,6 +47,42 @@ public:
return timestamp < other.timestamp;
}
void WriteHitsToCAENBinary(FILE * file, uint32_t header){
if( file == nullptr ) return;
uint32_t flag = 0;
uint8_t waveFormCode = 1; // input
// uint16_t header = 0xCAE1; // default to have the energy only
// if( energy2 > 0 ) header += 0x4;
// if( traceLength > 0 && withTrace ) header += 0x8;
size_t dummy;
dummy = fwrite(&sn, 2, 1, file);
dummy = fwrite(&ch, 2, 1, file);
uint64_t timestampPS = timestamp * 1000 + fineTime;
dummy = fwrite(&timestampPS, 8, 1, file);
dummy = fwrite(&energy, 2, 1, file);
if( (header & 0x4) ) dummy = fwrite(&energy2, 2, 1, file);
dummy = fwrite(&flag, 4, 1, file);
if( traceLength > 0 && (header & 0x8) ){
dummy = fwrite(&waveFormCode, 1, 1, file);
dummy = fwrite(&traceLength, 4, 1, file);
for( int j = 0; j < traceLength; j++ ){
dummy = fwrite(&(trace[j]), 2, 1, file);
}
}
if( dummy != 1 ) printf("write file error.\n");
}
};
#endif

View File

@ -17,6 +17,7 @@
#include "CustomWidgets.h"
#include "MultiBuilder.h"
#include "ClassInfluxDB.h"
#include "math.h"
/**************************************
@ -32,6 +33,7 @@ derivative class should define the SetUpCanvas() and UpdateHistogram();
#include "Histogram1D.h"
#include "Histogram2D.h"
//^==============================================
//^==============================================
class Analyzer : public QMainWindow{

296
analyzers/BeamTune.h Normal file
View File

@ -0,0 +1,296 @@
#ifndef BeamTune_h
#define BeamTune_h
/*********************************************
* This is online analyzer for PID, ANL
*
* Created by Khushi @ 2024-09-03
*
* ******************************************/
#include "Analyser.h"
#include <cmath>
#include "math.h"
#include <algorithm>
#include "TLine.h"
//#include <TMarker.h>
#include <vector>
#include <iostream>
class BeamTune : public Analyzer{
public:
BeamTune(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(2.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
//Histogram2D * hPID;
Histogram2D * hFrame; // dE versus E : ch1 versus ch4
Histogram2D * hFrame1; // dE versus E : ch1 versus ch4
//Histogram2D * hdEtotE; // dE versus totE : ch1 versus (ch1+ch4)
int tick2ns;
float s0, s1, s2, s3;
unsigned long long s_t0, s_t1, s_t2, s_t3;
float e0, e1, e2, e3, dE1, dE2;
unsigned long long t0, t1, t2, t3, dE1_t, dE2_t;
float ch1, ch4, ch7;
//unsigned long long t1, t4, t7;
};
inline void BeamTune::SetUpCanvas(){
setGeometry(0, 0, 2000, 1000);
//============ histograms
//hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this);
//layout->addWidget(hPID, 2, 0);
hFrame = new Histogram2D("X Map", "X-axis", "Y-axis", 100, -10, 110, 100, -0.8, 0.8, this);
layout->addWidget(hFrame, 0, 0, 1, 2);
hFrame1 = new Histogram2D("X Map", "X-axis", "Y-axis", 100, -10, 110, 100, -0.8, 0.8, this);
layout->addWidget(hFrame1, 1, 1, 1, 2);
/*
hdEdT = new Histogram2D("dE vs TOF", "TOF [ns]", "dE", 100, 0, 500, 100, 0, 4000, this);
layout->addWidget(hdEdT, 1, 3);
hdEtotE = new Histogram2D("dE vs TotE", "TotE[ch]", "dE[ch]", 500, 0, 10000, 500, 0, 10000, this);
layout->addWidget(hdEtotE, 1, 0, 1, 2);
*/
}
inline void BeamTune::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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 = hFrame->GetCutList();
const int nCut1 = cutList1.count();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
*/
/*
QList<QPolygonF> cutList2 = hdEtotE->GetCutList();
const int nCut2 = cutList2.count();
unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0};
unsigned int count2[nCut2]={0};
*/
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
e0 = 0;
e1 = 0;
e2 = 0;
e3 = 0;
t0 = 0;
t1 = 0;
t2 = 0;
t3 = 0;
s0 = 0;
s1 = 0;
s2 = 0;
s3 = 0;
s_t0 = 0;
s_t1 = 0;
s_t2 = 0;
s_t3 = 0;
//std::vector<TLine*> lines; // Store lines to draw after the loop
//std::vector<TMarker*> markers; // Store markers to draw after the loop
//int lineCount = 0; // Counter to keep track of the number of lines
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 2 ) {s0 = event[k].energy; s_t0 = event[k].timestamp;} //
if( event[k].ch == 3 ) {s1= event[k].energy; s_t1 = event[k].timestamp;} // The 4 output signals from the
if( event[k].ch == 4 ) {s2 = event[k].energy; s_t2 = event[k].timestamp;} // MCP detector
if( event[k].ch == 5 ) {s3= event[k].energy; s_t3 = event[k].timestamp;} //
if( event[k].ch == 10 ) {e0 = event[k].energy; t0 = event[k].timestamp;} //
if( event[k].ch == 11 ) {e1= event[k].energy; t1 = event[k].timestamp;} // The 4 output signals from the
if( event[k].ch == 12 ) {e2 = event[k].energy; t2 = event[k].timestamp;} // position sensitive E detector
if( event[k].ch == 13 ) {e3= event[k].energy; t3 = event[k].timestamp;} //
}
if (s0>10 && s1>10 && s2>10 && s3>10 && e0>10 && e1>10 && e2>10 && e3>10) {
float_t rotation_angle = 31.;
double_t Xr = (((s1+s2)/(s0+s1+s2+s3))-0.51)*cos(-rotation_angle*M_PI/180)-(((s2+s3)/(s0+s1+s2+s3))-0.51)*sin(-rotation_angle*M_PI/180);
double_t Yr = (((s1+s2)/(s0+s1+s2+s3))-0.51)*sin(-rotation_angle*M_PI/180)+(((s2+s3)/(s0+s1+s2+s3))-0.51)*cos(-rotation_angle*M_PI/180);
double_t X2 = ((e0-e1)/(e0+e1)); // PSD X position
double_t Y2 = ((e3-e2)/(e2+e3)); // PSD Y position
// printf("(E, dE) = (%f, %f)\n", E, dE);
// Create the line and store it in the vector
TLine *line = new TLine(Xr, Yr, X2, Y2);
//line->SetLineColor(kBlack);
// Set line color based on Y2 value
/*
if (Y2 > 0) {
line->SetLineColor(kPink); // Pink color if Y2 > 0
} else {
line->SetLineColor(kBlack); // Black otherwise
}
*/
//lines.push_back(line);
//lineCount++; // Increment the counter
//Create markers at the start and end of the line
//TMarker *startMarker = new TMarker(Xr, Yr, kFullCircle);
//startMarker->SetMarkerColor(kRed);
//startMarker->SetMarkerSize(0.1);
//markers.push_back(startMarker);
//TMarker *endMarker = new TMarker(X2, Y2, kFullCircle);
//endMarker->SetMarkerColor(kGreen);
//endMarker->SetMarkerSize(0.2);
//markers.push_back(endMarker);
hFrame->Fill(Xr,Yr, sX2,Y2);
hFrame1->Fill(X2,Y2);
// Draw all the lines after the loop
//for (auto line : lines) {
// line->Draw();
//}
// Draw all the markers after the lines
//for (auto marker : markers) {
// marker->Draw();
//}
//gStyle->SetOptStat(0000000);
//hdEtotE->Fill(ch1*0.25*0.25 + ch4,ch1);
}
//check events inside any Graphical cut and extract the rate
/*
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin[p] ) tMin[p] = t1;
if( t1 > tMax[p] ) tMax[p] = t1;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin1[p] ) tMin1[p] = t1;
if( t1 > tMax1[p] ) tMax1[p] = t1;
count1[p] ++;
//printf("hdEE.... %d \n", count1[p]);
}
}
for(int p = 0; p < cutList2.count(); p++ ){
if( cutList2[p].isEmpty() ) continue;
if( cutList2[p].containsPoint(QPointF(ch1+ch4,ch1), Qt::OddEvenFill) ){
if( t1 < tMin2[p] ) tMin2[p] = t1;
if( t1 > tMax2[p] ) tMax2[p] = t1;
count2[p] ++;
//printf("hdEtotE.... %d \n", count2[p]);
}
}
*/
}
/*
for(int p = 0; p < cutList2.count(); p++ ){
printf("hdEE.... %d %d \n", p, count1[p]);
}
*/
//hPID->UpdatePlot();
hFrame->UpdatePlot();
hFrame1->UpdatePlot();
//hdEtotE->UpdatePlot();
/*
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
*/
}
#endif

231
analyzers/Cross.h Normal file
View File

@ -0,0 +1,231 @@
#ifndef Cross_h
#define Cross_h
/*********************************************
* This is online analyzer for PID, ANL
*
* Created by Khushi @ 2024-09-03
*
* ******************************************/
#include "Analyser.h"
class Cross : public Analyzer{
public:
Cross(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(2.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
//Histogram2D * hPID;
Histogram1D * hdE; // raw dE (ch=1): ch1
Histogram1D * hE; // raw E (ch=4) : ch4
Histogram1D * hdT; // raw dT (ch=7): ch7
Histogram1D * hTotE; // total energy (dE+E): ch1+ch4
Histogram1D * hTWin; // coincidence time window TWin: (t4-t1)*1e9
Histogram2D * hdEE; // dE versus E : ch1 versus ch4
Histogram2D * hdEtotE; // dE versus totE : ch1 versus (ch1+ch4)
Histogram2D * hdEdT; // dE versus TOF: ch1 versus (t7-t1)*1e9
int tick2ns;
float ch1, ch4, ch7;
unsigned long long t1, t4, t7;
};
inline void Cross::SetUpCanvas(){
setGeometry(0, 0, 2000, 1000);
//============ histograms
//hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this);
//layout->addWidget(hPID, 2, 0);
hdEE = new Histogram2D("dE vs E", "E[ch]", "dE[ch]", 500, -100, 10000, 500, -100, 10000, this);
layout->addWidget(hdEE, 0, 0, 1, 2);
hdE = new Histogram1D("raw dE (ch=1)", "dE [ch]", 300, 0, 8000, this);
layout->addWidget(hdE, 0, 2);
hdEdT = new Histogram2D("dE vs TOF", "TOF [ns]", "dE", 100, 0, 500, 100, 0, 4000, this);
layout->addWidget(hdEdT, 1, 3);
hE = new Histogram1D("raw E (ch=4)", "E [ch]", 300, 0, 10000, this);
layout->addWidget(hE, 0, 3);
hdEtotE = new Histogram2D("dE vs TotE", "TotE[ch]", "dE[ch]", 500, 0, 10000, 500, 0, 10000, this);
layout->addWidget(hdEtotE, 1, 0, 1, 2);
hdT = new Histogram1D("raw dT (ch=7)", "dT [ch]", 300, 0, 1000, this);
layout->addWidget(hdT, 1, 2);
hTotE = new Histogram1D("total energy (dE+E)", "TotE [ch]", 300, 0, 16000, this);
layout->addWidget(hTotE, 0, 4);
hTWin = new Histogram1D("coincidence time window", "TWin [ns]", 300, 0, 500, this);
layout->addWidget(hTWin, 1, 4);
}
inline void Cross::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
QList<QPolygonF> cutList2 = hdEtotE->GetCutList();
const int nCut2 = cutList2.count();
unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0};
unsigned int count2[nCut2]={0};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 6 ) {ch1 = event[k].energy; t1 = event[k].timestamp;} // Reads channel 6 of the digitizer corresponding to dE
if( event[k].ch == 7 ) {ch4 = event[k].energy; t4 = event[k].timestamp;} // Reads channel 7 of the digitizer corresponding to E
if( event[k].ch == 1 ) {ch7 = event[k].energy; t7 = event[k].timestamp;}
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
//hPID->Fill(ch4 , ch1); // x, y
//etotal = ch1*0.25*0.25 + ch4
hdE->Fill(ch1);
hE->Fill(ch4);
hdT->Fill(ch7);
hTotE->Fill(ch1*0.25*0.25 + ch4);
hdEE->Fill(ch4,ch1);
hdEtotE->Fill(ch1*0.25*0.25 + ch4,ch1);
hdEdT->Fill((t7-t1)*1e9,ch1);
hTWin->Fill((t4-t1)*1e9);
//check events inside any Graphical cut and extract the rate
/*
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin[p] ) tMin[p] = t1;
if( t1 > tMax[p] ) tMax[p] = t1;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
*/
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin1[p] ) tMin1[p] = t1;
if( t1 > tMax1[p] ) tMax1[p] = t1;
count1[p] ++;
//printf("hdEE.... %d \n", count1[p]);
}
}
for(int p = 0; p < cutList2.count(); p++ ){
if( cutList2[p].isEmpty() ) continue;
if( cutList2[p].containsPoint(QPointF(ch1+ch4,ch1), Qt::OddEvenFill) ){
if( t1 < tMin2[p] ) tMin2[p] = t1;
if( t1 > tMax2[p] ) tMax2[p] = t1;
count2[p] ++;
//printf("hdEtotE.... %d \n", count2[p]);
}
}
}
for(int p = 0; p < cutList2.count(); p++ ){
printf("hdEE.... %d %d \n", p, count1[p]);
}
//hPID->UpdatePlot();
hdE->UpdatePlot();
hE->UpdatePlot();
hdT->UpdatePlot();
hTotE->UpdatePlot();
hdEE->UpdatePlot();
hdEtotE->UpdatePlot();
hdEdT->UpdatePlot();
hTWin->UpdatePlot();
/*
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
*/
}
#endif

260
analyzers/MCP.h Normal file
View File

@ -0,0 +1,260 @@
#ifndef MCP_h
#define MCP_h
/*********************************************
* This is online analyzer for MCP, ANL
*
* Created by Khushi @ 2024-03-27
*
* ******************************************/
#include "Analyser.h"
#include <cmath>
#include "math.h"
#include <algorithm>
//#define M_PI 3.14159265
class MCP : public Analyzer{
public:
MCP(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(2.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500); //ns
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
Histogram2D * hPID;
//Histogram2D * hXX; // X1 versus X2 : e[1] versus e[0]
//Histogram2D * hYY; // Y1 versus Y2 : e[3] versus e[2]
Histogram1D * hX; // X position:((e[0]+e[1])/(e[0]+e[1]+e[2]+e[3]))
Histogram1D * hY; // Y position:((e[2]+e[3])/((e[0]+e[1]+e[2]+e[3])))
Histogram1D * hXr; // X position angle rotated
Histogram1D * hYr; // Y position angle rotated
Histogram2D * hXY; // 2D position plot: ((e[2]+e[3])/((e[0]+e[1]+e[2]+e[3]))) versus ((e[0]+e[1])/(e[0]+e[1]+e[2]+e[3]))
Histogram2D * hXYr;
Histogram1D * he0; // e0: signal 0
Histogram1D * he1; // e1: signal 1
Histogram1D * he2; // e2: signal 2
Histogram1D * he3; // e3: signal 3
Histogram1D * ht; // time window
int tick2ns;
float dE, E;
unsigned long long dE_t, E_t;
float e0, e1, e2, e3;
unsigned long long t0, t1, t2, t3;
};
inline void MCP::SetUpCanvas(){
setGeometry(0, 0, 2000, 800);
//============ histograms
hPID = new Histogram2D("MCP", "E", "dE", 100, 0, 5000, 100, 0, 5000, this);
layout->addWidget(hPID, 0, 0);
hXYr = new Histogram2D("2D rot posi", "Xr position", "Yr position", 200, -0.5, 0.5, 200, -0.5, 0.5, this);
layout->addWidget(hXYr, 0, 1);
hXY = new Histogram2D("2D position plot", "X position", "Y position", 500, 0, 1, 500, 0, 1, this);
layout->addWidget(hXY, 0, 2);
ht = new Histogram1D("Time Window", "t", 50, 0, 500, this);
layout->addWidget(ht, 0, 3);
hX = new Histogram1D("X position", "X", 250, 0, 1, this);
layout->addWidget(hX, 2, 0);
hY = new Histogram1D("Y position", "Y", 250, 0, 1, this);
layout->addWidget(hY, 2, 1);
hXr = new Histogram1D("Angle rot X posi", "Xr", 250, -0.5, 0.5, this);
layout->addWidget(hXr, 2, 2);
hYr = new Histogram1D("Angle rot Y posi", "Yr", 250, -0.5, 0.5, this);
layout->addWidget(hYr, 2, 3);
// UNCOMMENT FOLLOWING 8 LINES TO SEE INDIVIDUAL SIGNALS
he0 = new Histogram1D("Signal 0", "e0", 200, 0, 8000, this);
layout->addWidget(he0, 1, 0);
he1 = new Histogram1D("Signal 1", "e1", 200, 0, 8000, this);
layout->addWidget(he1, 1, 1);
he2 = new Histogram1D("Signal 2", "e2", 200, 0, 8000, this);
layout->addWidget(he2, 1, 2);
he3 = new Histogram1D("Signal 3", "e3", 200, 0, 8000, this);
layout->addWidget(he3, 1, 3);
//
}
inline void MCP::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
//if( event.size() < 2 ) return;
cout<< "event size " << event.size() <<endl;
e0 = 0;
e1 = 0;
e2 = 0;
e3 = 0;
t0 = 0;
t1 = 0;
t2 = 0;
t3 = 0;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 2 ) {dE = event[k].energy; dE_t = event[k].timestamp;}
if( event[k].ch == 2 ) {E = event[k].energy; E_t = event[k].timestamp;}
if( event[k].ch == 2 ) {e0 = event[k].energy; t0 = event[k].timestamp;}
if( event[k].ch == 3 ) {e1= event[k].energy; t1 = event[k].timestamp;}
if( event[k].ch == 4 ) {e2 = event[k].energy; t2 = event[k].timestamp;}
if( event[k].ch == 5 ) {e3= event[k].energy; t3 = event[k].timestamp;}
}
if (e0>10 && e1>10 && e2>10 && e3>10) {
float_t rotation_angle = 31.;
double_t Xr = (((e1+e2)/(e0+e1+e2+e3))-0.51)*cos(-rotation_angle*M_PI/180)-(((e2+e3)/(e0+e1+e2+e3))-0.51)*sin(-rotation_angle*M_PI/180);
double_t Yr = (((e1+e2)/(e0+e1+e2+e3))-0.51)*sin(-rotation_angle*M_PI/180)+(((e2+e3)/(e0+e1+e2+e3))-0.51)*cos(-rotation_angle*M_PI/180);
hPID->Fill(E + RandomGauss(0, 100), dE+ RandomGauss(0, 100)); // x, y
hXY->Fill(((e1+e2)/(e0+e1+e2+e3)),((e2+e3)/(e0+e1+e2+e3)));
hXYr->Fill(Xr,Yr);
hX->Fill(((e1+e2)/(e0+e1+e2+e3)));
hY->Fill(((e2+e3)/(e0+e1+e2+e3)));
hXr->Fill(Xr);
hYr->Fill(Yr);
}
he0->Fill(e0);
he1->Fill(e1);
he2->Fill(e2);
he3->Fill(e3);
ht->Fill(max(max(t0,t1),max(t2,t3))-min(min(t0,t1),min(t2,t3)));
// cout << "t0: " << t0 << endl;
// cout << "t1: " << t1 << endl;
// cout << "t2: " << t2 << endl;
// cout << "t3: " << t3 << endl;
// cout << "time window " << max(max(t0,t1),max(t2,t3))-min(min(t0,t1),min(t2,t3)) <<endl;
// cout <<"---------------------" << endl;
//check events inside any Graphical cut and extract the rate
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(E, dE), Qt::OddEvenFill) ){
if( dE_t < tMin[p] ) tMin[p] = dE_t;
if( dE_t > tMax[p] ) tMax[p] = dE_t;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
}
hPID->UpdatePlot();
//hXX->UpdatePlot();//
//hYY->UpdatePlot();
hXY->UpdatePlot();
hXYr->UpdatePlot();
hX->UpdatePlot();
hY->UpdatePlot();
hXr->UpdatePlot();
hYr->UpdatePlot();
he0->UpdatePlot();
he1->UpdatePlot();
he2->UpdatePlot();
he3->UpdatePlot();
ht->UpdatePlot();
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
}
#endif

362
analyzers/MCPandPSD.h Normal file
View File

@ -0,0 +1,362 @@
#ifndef MCPandPSD_h
#define MCPandPSD_h
/*********************************************
* This is online analyzer for RASIOR, ANL
*
* Created by Ryan @ 2023-10-16
*
* ******************************************/
#include "Analyser.h"
#include <cmath>
#include "math.h"
#include <algorithm>
class MCPandPSD : public Analyzer{
public:
MCPandPSD(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(4.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
//Histogram2D * hPID;
Histogram2D * hXYE; // 2D energy plot: e[2]+e[3] versus e[0]+e[1]
Histogram1D * hX; // X position:((e[0]-e[1])/(e[0]+e[1]))
Histogram1D * hY; // Y position:((e[2]-e[3])/(e[2]+e[3]))
Histogram1D * hXmcp; // X position
Histogram1D * hYmcp; // Y position
Histogram2D * hXY; // 2D position plot: ((e[2]-e[3])/(e[2]+e[3])) versus ((e[0]-e[1])/(e[0]+e[1]))
Histogram2D * hXYMCP; // 2D position plot for MCP: ((e[2]+e[3])/((e[0]+e[1]+e[2]+e[3]))) versus ((e[0]+e[1])/(e[0]+e[1]+e[2]+e[3]))
Histogram2D * hXYr; // 2D position plot rotated for MCP:
Histogram2D * hXEdE1; //X energy versus dE signal 1
Histogram2D * hYEdE1; //Y energy versus dE signal 1
Histogram2D * hXEdE2; //X energy versus dE signal 2
Histogram2D * hYEdE2; //Y energy versus dE signal 2
/*
Histogram1D * he0; // e0: signal 0 from PSD
Histogram1D * he1; // e1: signal 1 from PSD
Histogram1D * he2; // e2: signal 2 from PSD
Histogram1D * he3; // e3: signal 3 from PSD
Histogram1D * hmcp0; // s0: signal 0 from MCP
Histogram1D * hmcp1; // s1: signal 1 from MCP
Histogram1D * hmcp2; // s2: signal 2 from MCP
Histogram1D * hmcp3; // s3: signal 3 from MCP
*/
int tick2ns;
//float dE, E;
//unsigned long long dE_t, E_t;
float e0, e1, e2, e3, dE1, dE2;
unsigned long long t0, t1, t2, t3, dE1_t, dE2_t;
float s0, s1, s2, s3;
unsigned long long s_t0, s_t1, s_t2, s_t3;
};
inline void MCPandPSD::SetUpCanvas(){
setGeometry(0, 0, 1500, 2000);
//============ histograms
//hPID = new Histogram2D("RAISOR2", "E", "dE", 100, 0, 11000, 100, 0, 11000, this);
//layout->addWidget(hPID, 0, 0);
hXY = new Histogram2D("2D position plot PSD_E", "X position", "Y position", 200, -1, 1, 200, -1, 1, this);
layout->addWidget(hXY, 0, 0);
hX = new Histogram1D("X position", "X", 300, -1, 1, this);
layout->addWidget(hX, 0, 1);
hY = new Histogram1D("Y position", "Y", 300, -1, 1, this);
layout->addWidget(hY, 0, 2);
/*
he0 = new Histogram1D("PSD_E 0", "e0", 200, 0, 8000, this);
layout->addWidget(he0, 0, 1);
he1 = new Histogram1D("PSD_E 1", "e1", 200, 0, 8000, this);
layout->addWidget(he1, 0, 2);
he2 = new Histogram1D("PSD_E 2", "e2", 200, 0, 8000, this);
layout->addWidget(he2, 0, 3);
he3 = new Histogram1D("PSD_E 3", "e3", 200, 0, 8000, this);
layout->addWidget(he3, 0, 4);
*/
hXYMCP = new Histogram2D("2D position MCP", "X position", "Y position", 500, 0, 1, 500, 0, 1, this);
layout->addWidget(hXYMCP, 1, 1);
hXYr = new Histogram2D("2D rot pos MCP", "Xr position", "Yr position", 200, -0.5, 0.5, 200, -0.5, 0.5, this);
layout->addWidget(hXYr, 1, 0);
/*
hmcp0 = new Histogram1D("MCP 0", "s0", 200, 0, 8000, this);
layout->addWidget(hmcp0, 1, 1);
hmcp1 = new Histogram1D("MCP 1", "s1", 200, 0, 8000, this);
layout->addWidget(hmcp1, 1, 2);
hmcp2 = new Histogram1D("MCP 2", "s2", 200, 0, 8000, this);
layout->addWidget(hmcp2, 1, 3);
hmcp3 = new Histogram1D("MCP 3", "s3", 200, 0, 8000, this);
layout->addWidget(hmcp3, 1, 4);
*/
hXmcp = new Histogram1D("X pos rot MCP", "X", 250, -0.5, 0.5, this);
layout->addWidget(hXmcp, 1, 2);
hYmcp = new Histogram1D("Y pos rot MCP", "Y", 250, -0.5, 0.5, this);
layout->addWidget(hYmcp, 1, 3);
hXEdE1 = new Histogram2D("X energy versus dE signal 1", "Ex", "dE signal 1", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hXEdE1, 2, 0);
hYEdE1 = new Histogram2D("Y energy versus dE signal 1", "Ey", "dE signal 1", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hYEdE1, 2, 1);
hXEdE2 = new Histogram2D("X energy versus dE signal 2", "Ex", "dE signal 2", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hXEdE2, 2, 2);
hYEdE2 = new Histogram2D("Y energy versus dE signal 2", "Ey", "dE signal 2", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hYEdE2, 2, 3);
hXYE = new Histogram2D("2D energy plot", "Ex", "Ey", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hXYE, 0, 3);
}
inline void MCPandPSD::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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 = hXEdE1->GetCutList();
const int nCut1 = cutList1.count();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
QList<QPolygonF> cutList2 = hYEdE1->GetCutList();
const int nCut2 = cutList2.count();
unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0};
unsigned int count2[nCut2]={0};
QList<QPolygonF> cutList3 = hXY->GetCutList();
const int nCut3 = cutList3.count();
unsigned long long tMin3[nCut3] = {0xFFFFFFFFFFFFFFFF}, tMax3[nCut3] = {0};
unsigned int count3[nCut3]={0};
*/
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
if( event.size() == 0 ) return;
//if( event.size() < 2 ) return;
cout<< "event size " << event.size() <<endl;
s0 = 0;
s1 = 0;
s2 = 0;
s3 = 0;
s_t0 = 0;
s_t1 = 0;
s_t2 = 0;
s_t3 = 0;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 2 ) {s0 = event[k].energy; s_t0 = event[k].timestamp;} //
if( event[k].ch == 3 ) {s1= event[k].energy; s_t1 = event[k].timestamp;} // The 4 output signals from the
if( event[k].ch == 4 ) {s2 = event[k].energy; s_t2 = event[k].timestamp;} // MCP detector
if( event[k].ch == 5 ) {s3= event[k].energy; s_t3 = event[k].timestamp;} //
if( event[k].ch == 10 ) {e0 = event[k].energy; t0 = event[k].timestamp;} //
if( event[k].ch == 11 ) {e1= event[k].energy; t1 = event[k].timestamp;} // The 4 output signals from the
if( event[k].ch == 12 ) {e2 = event[k].energy; t2 = event[k].timestamp;} // position sensitive E detector
if( event[k].ch == 13 ) {e3= event[k].energy; t3 = event[k].timestamp;} //
if( event[k].ch == 14 ) {dE1 = event[k].energy; dE1_t = event[k].timestamp;} // The 2 output signals from the
if( event[k].ch == 15 ) {dE2= event[k].energy; dE2_t = event[k].timestamp;} // square dE detector
}
if (s0>10 && s1>10 && s2>10 && s3>10) {
float_t rotation_angle = 31.;
double_t Xr = (((s1+s2)/(s0+s1+s2+s3))-0.51)*cos(-rotation_angle*M_PI/180)-(((s2+s3)/(s0+s1+s2+s3))-0.51)*sin(-rotation_angle*M_PI/180);
double_t Yr = (((s1+s2)/(s0+s1+s2+s3))-0.51)*sin(-rotation_angle*M_PI/180)+(((s2+s3)/(s0+s1+s2+s3))-0.51)*cos(-rotation_angle*M_PI/180);
// printf("(E, dE) = (%f, %f)\n", E, dE);
//hPID->Fill(E + RandomGauss(0, 100), dE+ RandomGauss(0, 100)); // x, y
hXY->Fill(((e0-e1)/(e0+e1)),((e3-e2)/(e2+e3)));
hXYMCP->Fill(((s1+s2)/(s0+s1+s2+s3)),((s2+s3)/(s0+s1+s2+s3)));
hX->Fill(((e0-e1)/(e0+e1)));
hY->Fill(((e3-e2)/(e2+e3)));
hXmcp->Fill(Xr);
hYmcp->Fill(Yr);
hXEdE1->Fill((e0+e1),dE1);
hYEdE1->Fill(e2+e3,dE1);
hXEdE2->Fill(e0+e1,dE2);
hYEdE2->Fill(e2+e3,dE2);
hXYE->Fill(e0+e1,e2+e3);
hXYr->Fill(Xr,Yr);
}
/*
he0->Fill(e0);
he1->Fill(e1);
he2->Fill(e2);
he3->Fill(e3);
hmcp0->Fill(s0);
hmcp1->Fill(s1);
hmcp2->Fill(s2);
hmcp3->Fill(s3);
*/
//check events inside any Graphical cut and extract the rate
/*
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(E, dE), Qt::OddEvenFill) ){
if( dE_t < tMin[p] ) tMin[p] = dE_t;
if( dE_t > tMax[p] ) tMax[p] = dE_t;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF((e0+e1), dE1), Qt::OddEvenFill) ){
if( dE1_t < tMin1[p] ) tMin1[p] = dE1_t;
if( dE1_t > tMax1[p] ) tMax1[p] = dE1_t;
count1[p] ++;
//printf("hXX.... %d \n", count1[p]);
}
}
for(int p = 0; p < cutList2.count(); p++ ){
if( cutList2[p].isEmpty() ) continue;
if( cutList2[p].containsPoint(QPointF((e2+e3), dE1), Qt::OddEvenFill) ){
if( dE1_t < tMin2[p] ) tMin2[p] = dE1_t;
if( dE1_t > tMax2[p] ) tMax2[p] = dE1_t;
count2[p] ++;
//printf("hXX.... %d \n", count2[p]);
}
}
for(int p = 0; p < cutList3.count(); p++ ){
if( cutList3[p].isEmpty() ) continue;
if( cutList3[p].containsPoint(QPointF(((e0-e1)/(e0+e1)), ((e2-e3)/(e2+e3))), Qt::OddEvenFill) ){
if( ((t2-t3)/(t2+t3)) < tMin3[p] ) tMin3[p] = ((t2-t3)/(t2+t3));
if( ((t2-t3)/(t2+t3)) > tMax3[p] ) tMax3[p] = ((t2-t3)/(t2+t3));
count3[p] ++;
//printf("hXX.... %d \n", count3[p]);
}
}
*/
}
//hPID->UpdatePlot();
hXY->UpdatePlot();
hXYr->UpdatePlot();
hXYMCP->UpdatePlot();
hX->UpdatePlot();
hY->UpdatePlot();
hXmcp->UpdatePlot();
hYmcp->UpdatePlot();
hXEdE1->UpdatePlot();
hYEdE1->UpdatePlot();
hXEdE2->UpdatePlot();
hYEdE2->UpdatePlot();
hXYE->UpdatePlot();
/*
he0->UpdatePlot();
he1->UpdatePlot();
he2->UpdatePlot();
he3->UpdatePlot();
hmcp0->UpdatePlot();
hmcp1->UpdatePlot();
hmcp2->UpdatePlot();
hmcp3->UpdatePlot();
*/
//========== output to Influx
/*
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
*/
}
#endif

231
analyzers/PID.h Normal file
View File

@ -0,0 +1,231 @@
#ifndef PID_h
#define PID_h
/*********************************************
* This is online analyzer for PID, ANL
*
* Created by Khushi @ 2024-03-27
*
* ******************************************/
#include "Analyser.h"
class PID : public Analyzer{
public:
PID(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(2.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
//Histogram2D * hPID;
Histogram1D * hdE; // raw dE (ch=1): ch1
Histogram1D * hE; // raw E (ch=4) : ch4
Histogram1D * hdT; // raw dT (ch=7): ch7
Histogram1D * hTotE; // total energy (dE+E): ch1+ch4
Histogram1D * hTWin; // coincidence time window TWin: (t4-t1)*1e9
Histogram2D * hdEE; // dE versus E : ch1 versus ch4
Histogram2D * hdEtotE; // dE versus totE : ch1 versus (ch1+ch4)
Histogram2D * hdEdT; // dE versus TOF: ch1 versus (t7-t1)*1e9
int tick2ns;
float ch1, ch4, ch7;
unsigned long long t1, t4, t7;
};
inline void PID::SetUpCanvas(){
setGeometry(0, 0, 2000, 1000);
//============ histograms
//hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this);
//layout->addWidget(hPID, 2, 0);
hdEE = new Histogram2D("dE vs E", "E[ch]", "dE[ch]", 500, -100, 10000, 500, -100, 10000, this);
layout->addWidget(hdEE, 0, 0, 1, 2);
hdE = new Histogram1D("raw dE (ch=1)", "dE [ch]", 300, 0, 8000, this);
layout->addWidget(hdE, 0, 2);
hdEdT = new Histogram2D("dE vs TOF", "TOF [ns]", "dE", 100, 0, 500, 100, 0, 4000, this);
layout->addWidget(hdEdT, 1, 3);
hE = new Histogram1D("raw E (ch=4)", "E [ch]", 300, 0, 10000, this);
layout->addWidget(hE, 0, 3);
hdEtotE = new Histogram2D("dE vs TotE", "TotE[ch]", "dE[ch]", 500, 0, 10000, 500, 0, 10000, this);
layout->addWidget(hdEtotE, 1, 0, 1, 2);
hdT = new Histogram1D("raw dT (ch=7)", "dT [ch]", 300, 0, 1000, this);
layout->addWidget(hdT, 1, 2);
hTotE = new Histogram1D("total energy (dE+E)", "TotE [ch]", 300, 0, 16000, this);
layout->addWidget(hTotE, 0, 4);
hTWin = new Histogram1D("coincidence time window", "TWin [ns]", 300, 0, 500, this);
layout->addWidget(hTWin, 1, 4);
}
inline void PID::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
QList<QPolygonF> cutList2 = hdEtotE->GetCutList();
const int nCut2 = cutList2.count();
unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0};
unsigned int count2[nCut2]={0};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 6 ) {ch1 = event[k].energy; t1 = event[k].timestamp;}
if( event[k].ch == 7 ) {ch4 = event[k].energy; t4 = event[k].timestamp;}
if( event[k].ch == 1 ) {ch7 = event[k].energy; t7 = event[k].timestamp;}
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
//hPID->Fill(ch4 , ch1); // x, y
//etotal = ch1*0.25*0.25 + ch4
hdE->Fill(ch1);
hE->Fill(ch4);
hdT->Fill(ch7);
hTotE->Fill(ch1*0.25*0.25 + ch4);
hdEE->Fill(ch4,ch1);
hdEtotE->Fill(ch1*0.25*0.25 + ch4,ch1);
hdEdT->Fill((t7-t1)*1e9,ch1);
hTWin->Fill((t4-t1)*1e9);
//check events inside any Graphical cut and extract the rate
/*
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin[p] ) tMin[p] = t1;
if( t1 > tMax[p] ) tMax[p] = t1;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
*/
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin1[p] ) tMin1[p] = t1;
if( t1 > tMax1[p] ) tMax1[p] = t1;
count1[p] ++;
//printf("hdEE.... %d \n", count1[p]);
}
}
for(int p = 0; p < cutList2.count(); p++ ){
if( cutList2[p].isEmpty() ) continue;
if( cutList2[p].containsPoint(QPointF(ch1+ch4,ch1), Qt::OddEvenFill) ){
if( t1 < tMin2[p] ) tMin2[p] = t1;
if( t1 > tMax2[p] ) tMax2[p] = t1;
count2[p] ++;
//printf("hdEtotE.... %d \n", count2[p]);
}
}
}
for(int p = 0; p < cutList2.count(); p++ ){
printf("hdEE.... %d %d \n", p, count1[p]);
}
//hPID->UpdatePlot();
hdE->UpdatePlot();
hE->UpdatePlot();
hdT->UpdatePlot();
hTotE->UpdatePlot();
hdEE->UpdatePlot();
hdEtotE->UpdatePlot();
hdEdT->UpdatePlot();
hTWin->UpdatePlot();
/*
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
*/
}
#endif

View File

@ -1,133 +0,0 @@
#ifndef RASIOR_h
#define RASIOR_h
/*********************************************
* This is online analyzer for RASIOR, ANL
*
* Created by Ryan @ 2023-10-16
*
* ******************************************/
#include "Analyser.h"
class RAISOR : public Analyzer{
public:
RAISOR(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(1.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
Histogram2D * hPID;
int tick2ns;
float dE, E;
unsigned long long dE_t, E_t;
};
inline void RAISOR::SetUpCanvas(){
setGeometry(0, 0, 500, 500);
//============ histograms
hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 20000, this);
layout->addWidget(hPID, 0, 0);
}
inline void RAISOR::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 0 ) {dE = event[k].energy; dE_t = event[k].timestamp;}
if( event[k].ch == 1 ) {E = event[k].energy; E_t = event[k].timestamp;}
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
hPID->Fill(E + RandomGauss(0, 100), dE+ RandomGauss(0, 100)); // x, y
//check events inside any Graphical cut and extract the rate
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(E, dE), Qt::OddEvenFill) ){
if( dE_t < tMin[p] ) tMin[p] = dE_t;
if( dE_t > tMax[p] ) tMax[p] = dE_t;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
}
hPID->UpdatePlot();
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
}
#endif

270
analyzers/RAISOR1.h Normal file
View File

@ -0,0 +1,270 @@
#ifndef RASIOR1_h
#define RASIOR1_h
/*********************************************
* This is online analyzer for RASIOR, ANL
*
* Created by Ryan @ 2023-10-16
*
* ******************************************/
#include "Analyser.h"
class RAISOR1 : public Analyzer{
public:
RAISOR1(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(1.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
Histogram2D * hPID;
Histogram2D * hXX; // X1 versus X2 : e[1] versus e[0]
Histogram2D * hYY; // Y1 versus Y2 : e[3] versus e[2]
Histogram1D * hXE; // X energy: e[0]+e[1]
Histogram1D * hYE; // Y energy: e[2]+e[3]
Histogram2D * hXYE; // 2D energy plot: e[2]+e[3] versus e[0]+e[1]
Histogram1D * hX; // X position:((e[0]-e[1])/(e[0]+e[1]))
Histogram1D * hY; // Y position:((e[2]-e[3])/(e[2]+e[3]))
Histogram2D * hXY; // 2D position plot: ((e[2]-e[3])/(e[2]+e[3])) versus ((e[0]-e[1])/(e[0]+e[1]))
Histogram2D * hXPE; // X position versus X energy: ((e[0]-e[1])/(e[0]+e[1])) versus (e[0]+e[1])
Histogram2D * hYPE; // Y position versus Y energy: ((e[2]-e[3])/(e[2]+e[3])) versus (e[2]+e[3])
//TH1F * hX1, * hX2, * hY1, *hY2;
Histogram2D * hXEdE1; //X energy versus dE signal 1
Histogram2D * hYEdE1; //Y energy versus dE signal 1
Histogram2D * hXEdE2; //X energy versus dE signal 2
Histogram2D * hYEdE2; //Y energy versus dE signal 2
Histogram1D * hX1, * hX2, * hY1, * hY2;
int chX1, chX2; // yellow, Red
int chY1, chY2; // Blue, White
int tick2ns;
float dE, E;
unsigned long long dE_t, E_t;
float e0, e1, e2, e3, dE1, dE2;
unsigned long long t0, t1, t2, t3, dE1_t, dE2_t;
//unsigned Int_t * energy;
//unsigned long energy;
/*
chX1 = 0; // left
chX2 = 1; // right
chY1 = 2; // top
chY2 = 3; // bottom
*/
};
inline void RAISOR1::SetUpCanvas(){
setGeometry(0, 0, 1500, 2000);
//============ histograms
hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this);
layout->addWidget(hPID, 0, 0);
hXY = new Histogram2D("2D position plot", "X position", "Y position", 100, -1, 1, 100, -1, 1, this);
layout->addWidget(hXY, 0, 1);
hXX = new Histogram2D("X1 versus X2", "X2", "X1", 100, 0, 5000, 100, 0, 5000, this);
layout->addWidget(hXX, 0, 2);
hYY = new Histogram2D("Y1 versus Y2", "Y2", "Y1", 100, 0, 3000, 100, 0, 3000, this);
layout->addWidget(hYY, 0, 3);
hXE = new Histogram1D("X energy", "Ex", 300, 0, 8000, this);
layout->addWidget(hXE, 1, 0);
hYE = new Histogram1D("Y energy", "Ey", 300, 0, 4000, this);
layout->addWidget(hYE, 1, 1);
hX = new Histogram1D("X position", "X", 300, -1, 1, this);
layout->addWidget(hX, 1, 2);
hY = new Histogram1D("Y position", "Y", 300, -1, 1, this);
layout->addWidget(hY, 1, 3);
hXPE = new Histogram2D("X energy versus X position", "X position", "X energy", 100, -1, 1, 100, -2000, 20000, this);
layout->addWidget(hXPE, 0, 4);
hYPE = new Histogram2D("Y energy versus Y position", "Y position", "Y energy", 100, -1, 1, 100, 0, 5000, this);
layout->addWidget(hYPE, 1, 4);
hXEdE1 = new Histogram2D("X energy versus dE signal 1", "Ex", "dE signal 1", 100, -200, 20000, 100, -200, 10000, this);
layout->addWidget(hXEdE1, 2, 0);
hYEdE1 = new Histogram2D("Y energy versus dE signal 1", "Ey", "dE signal 1", 100, 0, 6000, 100, 0, 6000, this);
layout->addWidget(hYEdE1, 2, 1);
hXEdE2 = new Histogram2D("X energy versus dE signal 2", "Ex", "dE signal 2", 100, -500, 20000, 100, -500, 15000, this);
layout->addWidget(hXEdE2, 2, 2);
hYEdE2 = new Histogram2D("Y energy versus dE signal 2", "Ey", "dE signal 2", 100, -500, 5000, 100, -500, 12000, this);
layout->addWidget(hYEdE2, 2, 3);
hXYE = new Histogram2D("2D energy plot", "Ex", "Ey", 100, 0, 10000, 100, 0, 6000, this);
layout->addWidget(hXYE, 2, 4);
}
inline void RAISOR1::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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 = hXX->GetCutList();
const int nCut1 = cutList1.count();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 8 ) {dE = event[k].energy; dE_t = event[k].timestamp;} // Surface Barrier dE detector
if( event[k].ch == 8 ) {E = event[k].energy; E_t = event[k].timestamp;} // Surface Barrier E detector
if( event[k].ch == 10 ) {e0 = event[k].energy; t0 = event[k].timestamp;} //
if( event[k].ch == 11 ) {e1= event[k].energy; t1 = event[k].timestamp;} // The 4 output signals from the
if( event[k].ch == 12 ) {e2 = event[k].energy; t2 = event[k].timestamp;} // position sensitive E detector
if( event[k].ch == 13 ) {e3= event[k].energy; t3 = event[k].timestamp;} //
if( event[k].ch == 14 ) {dE1 = event[k].energy; dE1_t = event[k].timestamp;} // The 2 output signals from the
if( event[k].ch == 15 ) {dE2= event[k].energy; dE2_t = event[k].timestamp;} // square dE detector
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
hPID->Fill(E + RandomGauss(0, 100), dE+ RandomGauss(0, 100)); // x, y
hXX->Fill(e1, e0); //
hYY->Fill(e3, e2);
hXY->Fill(((e0-e1)/(e0+e1)),((e2-e3)/(e2+e3)));
hXE->Fill(e0+e1);
hYE->Fill(e2+e3);
hX->Fill(((e0-e1)/(e0+e1)));
hY->Fill(((e2-e3)/(e2+e3)));
hXPE->Fill(((e0-e1)/(e0+e1)),(e0+e1));
hYPE->Fill(((e2-e3)/(e2+e3)),(e2+e3));
hXEdE1->Fill((e0+e1),dE1);
hYEdE1->Fill(e2+e3,dE1);
hXEdE2->Fill(e0+e1,dE2);
hYEdE2->Fill(e2+e3,dE2);
hXYE->Fill(e0+e1,e2+e3);
//check events inside any Graphical cut and extract the rate
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(E, dE), Qt::OddEvenFill) ){
if( dE_t < tMin[p] ) tMin[p] = dE_t;
if( dE_t > tMax[p] ) tMax[p] = dE_t;
count[p] ++;
printf("hPID.... %d \n", count[p]);
}
}
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF(e1, e0), Qt::OddEvenFill) ){
if( t0 < tMin1[p] ) tMin1[p] = t0;
if( t0 > tMax1[p] ) tMax1[p] = t0;
count1[p] ++;
printf("hXX.... %d \n", count1[p]);
}
}
}
hPID->UpdatePlot();
hXY->UpdatePlot();
hXX->UpdatePlot();
hYY->UpdatePlot();
hXE->UpdatePlot();
hYE->UpdatePlot();
hX->UpdatePlot();
hY->UpdatePlot();
hXPE->UpdatePlot();
hYPE->UpdatePlot();
hXEdE1->UpdatePlot();
hYEdE1->UpdatePlot();
hXEdE2->UpdatePlot();
hYEdE2->UpdatePlot();
hXYE->UpdatePlot();
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
}
#endif

298
analyzers/RAISOR2.h Normal file
View File

@ -0,0 +1,298 @@
#ifndef RASIOR2_h
#define RASIOR2_h
/*********************************************
* This is online analyzer for RASIOR, ANL
*
* Created by Ryan @ 2023-10-16
*
* ******************************************/
#include "Analyser.h"
class RAISOR2 : public Analyzer{
public:
RAISOR2(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(4.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
Histogram2D * hPID;
Histogram2D * hXX; // X1 versus X2 : e[1] versus e[0]
Histogram2D * hYY; // Y1 versus Y2 : e[3] versus e[2]
Histogram1D * hXE; // X energy: e[0]+e[1]
Histogram1D * hYE; // Y energy: e[2]+e[3]
Histogram2D * hXYE; // 2D energy plot: e[2]+e[3] versus e[0]+e[1]
Histogram1D * hX; // X position:((e[0]-e[1])/(e[0]+e[1]))
Histogram1D * hY; // Y position:((e[2]-e[3])/(e[2]+e[3]))
Histogram2D * hXY; // 2D position plot: ((e[2]-e[3])/(e[2]+e[3])) versus ((e[0]-e[1])/(e[0]+e[1]))
Histogram2D * hXPE; // X position versus X energy: ((e[0]-e[1])/(e[0]+e[1])) versus (e[0]+e[1])
Histogram2D * hYPE; // Y position versus Y energy: ((e[2]-e[3])/(e[2]+e[3])) versus (e[2]+e[3])
//TH1F * hX1, * hX2, * hY1, *hY2;
Histogram2D * hXEdE1; //X energy versus dE signal 1
Histogram2D * hYEdE1; //Y energy versus dE signal 1
Histogram2D * hXEdE2; //X energy versus dE signal 2
Histogram2D * hYEdE2; //Y energy versus dE signal 2
Histogram1D * hX1, * hX2, * hY1, * hY2;
int chX1, chX2; // yellow, Red
int chY1, chY2; // Blue, White
int tick2ns;
float dE, E;
unsigned long long dE_t, E_t;
float e0, e1, e2, e3, dE1, dE2;
unsigned long long t0, t1, t2, t3, dE1_t, dE2_t;
//unsigned Int_t * energy;
//unsigned long energy;
/*
chX1 = 0; // left
chX2 = 1; // right
chY1 = 2; // top
chY2 = 3; // bottom
*/
};
inline void RAISOR2::SetUpCanvas(){
setGeometry(0, 0, 1500, 2000);
//============ histograms
hPID = new Histogram2D("RAISOR2", "E", "dE", 100, 0, 11000, 100, 0, 11000, this);
layout->addWidget(hPID, 0, 0);
hXY = new Histogram2D("2D position plot", "X position", "Y position", 200, -1, 1, 200, -1, 1, this);
layout->addWidget(hXY, 0, 1);
hXX = new Histogram2D("X1 versus X2", "X2", "X1", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hXX, 0, 2);
hYY = new Histogram2D("Y1 versus Y2", "Y2", "Y1", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hYY, 0, 3);
hXE = new Histogram1D("X energy", "Ex", 300, 0, 8000, this);
layout->addWidget(hXE, 1, 0);
hYE = new Histogram1D("Y energy", "Ey", 300, 0, 8000, this);
layout->addWidget(hYE, 1, 1);
hX = new Histogram1D("X position", "X", 300, -1, 1, this);
layout->addWidget(hX, 1, 2);
hY = new Histogram1D("Y position", "Y", 300, -1, 1, this);
layout->addWidget(hY, 1, 3);
hXPE = new Histogram2D("X energy versus X position", "X position", "X energy", 100, -1, 1, 100, 0, 8000, this);
layout->addWidget(hXPE, 0, 4);
hYPE = new Histogram2D("Y energy versus Y position", "Y position", "Y energy", 100, -1, 1, 100, 0, 8000, this);
layout->addWidget(hYPE, 1, 4);
hXEdE1 = new Histogram2D("X energy versus dE signal 1", "Ex", "dE signal 1", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hXEdE1, 2, 0);
hYEdE1 = new Histogram2D("Y energy versus dE signal 1", "Ey", "dE signal 1", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hYEdE1, 2, 1);
hXEdE2 = new Histogram2D("X energy versus dE signal 2", "Ex", "dE signal 2", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hXEdE2, 2, 2);
hYEdE2 = new Histogram2D("Y energy versus dE signal 2", "Ey", "dE signal 2", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hYEdE2, 2, 3);
hXYE = new Histogram2D("2D energy plot", "Ex", "Ey", 100, 0, 8000, 100, 0, 8000, this);
layout->addWidget(hXYE, 2, 4);
}
inline void RAISOR2::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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 = hXEdE1->GetCutList();
const int nCut1 = cutList1.count();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
QList<QPolygonF> cutList2 = hYEdE1->GetCutList();
const int nCut2 = cutList2.count();
unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0};
unsigned int count2[nCut2]={0};
QList<QPolygonF> cutList3 = hXY->GetCutList();
const int nCut3 = cutList3.count();
unsigned long long tMin3[nCut3] = {0xFFFFFFFFFFFFFFFF}, tMax3[nCut3] = {0};
unsigned int count3[nCut3]={0};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 14 ) {dE = event[k].energy; dE_t = event[k].timestamp;} // Surface Barrier dE detector
if( event[k].ch == 15 ) {E = event[k].energy; E_t = event[k].timestamp;} // Surface Barrier E detector
if( event[k].ch == 10 ) {e0 = event[k].energy; t0 = event[k].timestamp;} //
if( event[k].ch == 11 ) {e1= event[k].energy; t1 = event[k].timestamp;} // The 4 output signals from the
if( event[k].ch == 12 ) {e2 = event[k].energy; t2 = event[k].timestamp;} // position sensitive E detector
if( event[k].ch == 13 ) {e3= event[k].energy; t3 = event[k].timestamp;} //
if( event[k].ch == 14 ) {dE1 = event[k].energy; dE1_t = event[k].timestamp;} // The 2 output signals from the
if( event[k].ch == 15 ) {dE2= event[k].energy; dE2_t = event[k].timestamp;} // square dE detector
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
hPID->Fill(E + RandomGauss(0, 100), dE+ RandomGauss(0, 100)); // x, y
hXX->Fill(e1 , e0); //
hYY->Fill(e3, e2);
hXY->Fill(((e0-e1)/(e0+e1)),((e3-e2)/(e2+e3)));
hXE->Fill(e0+e1);
hYE->Fill(e2+e3);
hX->Fill(((e0-e1)/(e0+e1))); // X position
hY->Fill(((e3-e2)/(e2+e3))); // Y position
hXPE->Fill(((e0-e1)/(e0+e1)),(e0+e1));
hYPE->Fill(((e3-e2)/(e2+e3)),(e2+e3));
hXEdE1->Fill((e0+e1),dE1);
hYEdE1->Fill(e2+e3,dE1);
hXEdE2->Fill(e0+e1,dE2);
hYEdE2->Fill(e2+e3,dE2);
hXYE->Fill(e0+e1,e2+e3);
//check events inside any Graphical cut and extract the rate
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(E, dE), Qt::OddEvenFill) ){
if( dE_t < tMin[p] ) tMin[p] = dE_t;
if( dE_t > tMax[p] ) tMax[p] = dE_t;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF((e0+e1), dE1), Qt::OddEvenFill) ){
if( dE1_t < tMin1[p] ) tMin1[p] = dE1_t;
if( dE1_t > tMax1[p] ) tMax1[p] = dE1_t;
count1[p] ++;
//printf("hXX.... %d \n", count1[p]);
}
}
for(int p = 0; p < cutList2.count(); p++ ){
if( cutList2[p].isEmpty() ) continue;
if( cutList2[p].containsPoint(QPointF((e2+e3), dE1), Qt::OddEvenFill) ){
if( dE1_t < tMin2[p] ) tMin2[p] = dE1_t;
if( dE1_t > tMax2[p] ) tMax2[p] = dE1_t;
count2[p] ++;
//printf("hXX.... %d \n", count2[p]);
}
}
for(int p = 0; p < cutList3.count(); p++ ){
if( cutList3[p].isEmpty() ) continue;
if( cutList3[p].containsPoint(QPointF(((e0-e1)/(e0+e1)), ((e2-e3)/(e2+e3))), Qt::OddEvenFill) ){
if( ((t2-t3)/(t2+t3)) < tMin3[p] ) tMin3[p] = ((t2-t3)/(t2+t3));
if( ((t2-t3)/(t2+t3)) > tMax3[p] ) tMax3[p] = ((t2-t3)/(t2+t3));
count3[p] ++;
//printf("hXX.... %d \n", count3[p]);
}
}
}
hPID->UpdatePlot();
hXY->UpdatePlot();
hXX->UpdatePlot();
hYY->UpdatePlot();
hXE->UpdatePlot(); // X Energy
hYE->UpdatePlot(); // Y Energy
hX->UpdatePlot(); // X position
hY->UpdatePlot(); // Y position
hXPE->UpdatePlot();
hYPE->UpdatePlot();
hXEdE1->UpdatePlot();
hYEdE1->UpdatePlot();
hXEdE2->UpdatePlot();
hYEdE2->UpdatePlot();
hXYE->UpdatePlot();
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
}
#endif

273
analyzers/TEST.h Normal file
View File

@ -0,0 +1,273 @@
#ifndef TEST_h
#define TEST_h
/*********************************************
* This is online analyzer for RASIOR, ANL
*
* Created by Ryan @ 2023-10-16
*
* ******************************************/
#include "Analyser.h"
class TEST : public Analyzer{
public:
TEST(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(4.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
Histogram2D * hPID;
Histogram2D * hXX; // X1 versus X2 : e[1] versus e[0]
Histogram2D * hYY; // Y1 versus Y2 : e[3] versus e[2]
Histogram1D * hXE; // X energy: e[0]+e[1]
Histogram1D * hYE; // Y energy: e[2]+e[3]
Histogram2D * hXYE; // 2D energy plot: e[2]+e[3] versus e[0]+e[1]
Histogram1D * hX; // X position:((e[0]-e[1])/(e[0]+e[1]))
Histogram1D * hY; // Y position:((e[2]-e[3])/(e[2]+e[3]))
Histogram2D * hXY; // 2D position plot: ((e[2]-e[3])/(e[2]+e[3])) versus ((e[0]-e[1])/(e[0]+e[1]))
Histogram2D * hXPE; // X position versus X energy: ((e[0]-e[1])/(e[0]+e[1])) versus (e[0]+e[1])
Histogram2D * hYPE; // Y position versus Y energy: ((e[2]-e[3])/(e[2]+e[3])) versus (e[2]+e[3])
//TH1F * hX1, * hX2, * hY1, *hY2;
Histogram2D * hXEdE1; //X energy versus dE signal 1
Histogram2D * hYEdE1; //Y energy versus dE signal 1
Histogram2D * hXEdE2; //X energy versus dE signal 2
Histogram2D * hYEdE2; //Y energy versus dE signal 2
Histogram1D * hX1, * hX2, * hY1, * hY2;
int chX1, chX2; // yellow, Red
int chY1, chY2; // Blue, White
int tick2ns;
float dE, E;
unsigned long long dE_t, E_t;
float e0, e1, e2, e3, dE1, dE2;
unsigned long long t0, t1, t2, t3, dE1_t, dE2_t;
//unsigned Int_t * energy;
//unsigned long energy;
/*
chX1 = 0; // left
chX2 = 1; // right
chY1 = 2; // top
chY2 = 3; // bottom
*/
};
inline void TEST::SetUpCanvas(){
setGeometry(0, 0, 1500, 2000);
//============ histograms
hPID = new Histogram2D("Test", "E", "dE", 100, 0, 11500, 100, 0, 11500, this);
layout->addWidget(hPID, 0, 0);
hXY = new Histogram2D("2D position plot", "X position", "Y position", 100, -100, 100, 100, -100, 100, this);
layout->addWidget(hXY, 0, 1);
hXX = new Histogram2D("X1 versus X2", "X2", "X1", 100, 0, 12500, 100, 0, 12500, this);
layout->addWidget(hXX, 0, 2);
hYY = new Histogram2D("Y1 versus Y2", "Y2", "Y1", 100, -2000, 12500, 100, -2000, 12500, this);
layout->addWidget(hYY, 0, 3);
hXE = new Histogram1D("X energy", "Ex", 300, -500, 25000, this);
layout->addWidget(hXE, 1, 0);
hYE = new Histogram1D("Y energy", "Ey", 300, -500, 25000, this);
layout->addWidget(hYE, 1, 1);
hX = new Histogram1D("X position", "X", 300, -1, 1, this);
layout->addWidget(hX, 1, 2);
hY = new Histogram1D("Y position", "Y", 300, -1, 1, this);
layout->addWidget(hY, 1, 3);
hXPE = new Histogram2D("X energy versus X position", "X position", "X energy", 100, -1, 1, 100, -2000, 25000, this);
layout->addWidget(hXPE, 0, 4);
hYPE = new Histogram2D("Y energy versus Y position", "Y position", "Y energy", 100, -1000, 1000, 100, -2000, 30000, this);
layout->addWidget(hYPE, 1, 4);
hXEdE1 = new Histogram2D("X energy versus dE signal 1", "Ex", "dE signal 1", 100, -500, 25000, 100, -200, 12500, this);
layout->addWidget(hXEdE1, 2, 0);
hYEdE1 = new Histogram2D("Y energy versus dE signal 1", "Ey", "dE signal 1", 100, -500, 25000, 100, -2000, 12500, this);
layout->addWidget(hYEdE1, 2, 1);
hXEdE2 = new Histogram2D("X energy versus dE signal 2", "Ex", "dE signal 2", 100, -500, 25000, 100, -500, 12500, this);
layout->addWidget(hXEdE2, 2, 2);
hYEdE2 = new Histogram2D("Y energy versus dE signal 2", "Ey", "dE signal 2", 100, -500, 25000, 100, -2000, 12500, this);
layout->addWidget(hYEdE2, 2, 3);
hXYE = new Histogram2D("2D energy plot", "Ex", "Ey", 100, 0, 25000, 100, 0, 30000, this);
layout->addWidget(hXYE, 2, 4);
}
inline void TEST::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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 = hXX->GetCutList();
const int nCut1 = cutList1.count();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 8 ) {dE = event[k].energy; dE_t = event[k].timestamp;} // Surface Barrier dE detector
if( event[k].ch == 8 ) {E = event[k].energy; E_t = event[k].timestamp;} // Surface Barrier E detector
if( event[k].ch == 8 ) {e0 = event[k].energy; t0 = event[k].timestamp;} //
if( event[k].ch == 8 ) {e1= event[k].energy; t1 = event[k].timestamp;} // The 4 output signals from the
if( event[k].ch == 8 ) {e2 = event[k].energy; t2 = event[k].timestamp;} // position sensitive E detector
if( event[k].ch == 8 ) {e3= event[k].energy; t3 = event[k].timestamp;} //
if( event[k].ch == 8 ) {dE1 = event[k].energy; dE1_t = event[k].timestamp;} // The 2 output signals from the
if( event[k].ch == 8 ) {dE2= event[k].energy; dE2_t = event[k].timestamp;} // square dE detector
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
hPID->Fill(E + RandomGauss(0, 100), dE + RandomGauss(0, 100)); // x, y
//hXX->Fill(e1 + RandomGauss(0, 100), e0 + RandomGauss(0, 100)); //
hXX->Fill(e1, e0 ); //
hYY->Fill(e3 + RandomGauss(0, 100), e2 + RandomGauss(0, 100));
hXY->Fill(((e0-e1)/(e0+e1)) + RandomGauss(0, 100),((e2-e3)/(e2+e3)) + RandomGauss(0, 100));
hXE->Fill(e0+e1);
hYE->Fill(e2+e3);
hX->Fill(((e0-e1)/(e0+e1)));
hY->Fill(((e2-e3)/(e2+e3)));
hXPE->Fill(((e0-e1)/(e0+e1)) + RandomGauss(0, 100),(e0+e1) + RandomGauss(0, 100));
hYPE->Fill(((e2-e3)/(e2+e3)) + RandomGauss(0, 100),(e2+e3) + RandomGauss(0, 100));
hXEdE1->Fill((e0+e1)+ RandomGauss(0, 100),dE1 + RandomGauss(0, 100));
hYEdE1->Fill((e2+e3) + RandomGauss(0, 100),dE1 + RandomGauss(0, 100));
hXEdE2->Fill((e0+e1)+ RandomGauss(0, 100),dE2 + RandomGauss(0, 100));
hYEdE2->Fill((e2+e3)+ RandomGauss(0, 100),dE2 + + RandomGauss(0, 100));
hXYE->Fill((e0+e1) + RandomGauss(0, 100),(e2+e3) + RandomGauss(0, 100));
//check events inside any Graphical cut and extract the rate
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(E, dE), Qt::OddEvenFill) ){
if( dE_t < tMin[p] ) tMin[p] = dE_t;
if( dE_t > tMax[p] ) tMax[p] = dE_t;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF(e1, e0), Qt::OddEvenFill) ){
if( t0 < tMin1[p] ) tMin1[p] = t0;
if( t0 > tMax1[p] ) tMax1[p] = t0;
count1[p] ++;
}
}
}
for(int p = 0; p < cutList1.count(); p++ ){
printf("hXX.... %d %d \n", p, count1[p]);
}
hPID->UpdatePlot();
hXY->UpdatePlot();
hXX->UpdatePlot();
hYY->UpdatePlot();
hXE->UpdatePlot();
hYE->UpdatePlot();
hX->UpdatePlot();
hY->UpdatePlot();
hXPE->UpdatePlot();
hYPE->UpdatePlot();
hXEdE1->UpdatePlot();
hYEdE1->UpdatePlot();
hXEdE2->UpdatePlot();
hYEdE2->UpdatePlot();
hXYE->UpdatePlot();
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
}
#endif

231
analyzers/Target.h Normal file
View File

@ -0,0 +1,231 @@
#ifndef Target_h
#define Target_h
/*********************************************
* This is online analyzer for PID, ANL
*
* Created by Khushi @ 2024-09-03
*
* ******************************************/
#include "Analyser.h"
class Target : public Analyzer{
public:
Target(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
SetUpdateTimeInSec(2.0);
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(500);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
dataBaseName = "testing";
SetUpCanvas(); // see below
};
void SetUpCanvas();
public slots:
void UpdateHistograms();
private:
MultiBuilder *evtbder;
//Histogram2D * hPID;
Histogram1D * hdE; // raw dE (ch=1): ch1
Histogram1D * hE; // raw E (ch=4) : ch4
Histogram1D * hdT; // raw dT (ch=7): ch7
Histogram1D * hTotE; // total energy (dE+E): ch1+ch4
Histogram1D * hTWin; // coincidence time window TWin: (t4-t1)*1e9
Histogram2D * hdEE; // dE versus E : ch1 versus ch4
Histogram2D * hdEtotE; // dE versus totE : ch1 versus (ch1+ch4)
Histogram2D * hdEdT; // dE versus TOF: ch1 versus (t7-t1)*1e9
int tick2ns;
float ch1, ch4, ch7;
unsigned long long t1, t4, t7;
};
inline void Target::SetUpCanvas(){
setGeometry(0, 0, 2000, 1000);
//============ histograms
//hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this);
//layout->addWidget(hPID, 2, 0);
hdEE = new Histogram2D("dE vs E", "E[ch]", "dE[ch]", 500, -100, 10000, 500, -100, 10000, this);
layout->addWidget(hdEE, 0, 0, 1, 2);
hdE = new Histogram1D("raw dE (ch=1)", "dE [ch]", 300, 0, 8000, this);
layout->addWidget(hdE, 0, 2);
hdEdT = new Histogram2D("dE vs TOF", "TOF [ns]", "dE", 100, 0, 500, 100, 0, 4000, this);
layout->addWidget(hdEdT, 1, 3);
hE = new Histogram1D("raw E (ch=4)", "E [ch]", 300, 0, 10000, this);
layout->addWidget(hE, 0, 3);
hdEtotE = new Histogram2D("dE vs TotE", "TotE[ch]", "dE[ch]", 500, 0, 10000, 500, 0, 10000, this);
layout->addWidget(hdEtotE, 1, 0, 1, 2);
hdT = new Histogram1D("raw dT (ch=7)", "dT [ch]", 300, 0, 1000, this);
layout->addWidget(hdT, 1, 2);
hTotE = new Histogram1D("total energy (dE+E)", "TotE [ch]", 300, 0, 16000, this);
layout->addWidget(hTotE, 0, 4);
hTWin = new Histogram1D("coincidence time window", "TWin [ns]", 300, 0, 500, this);
layout->addWidget(hTWin, 1, 4);
}
inline void Target::UpdateHistograms(){
if( this->isVisible() == false ) return;
BuildEvents(false); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
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();
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
unsigned int count1[nCut1]={0};
QList<QPolygonF> cutList2 = hdEtotE->GetCutList();
const int nCut2 = cutList2.count();
unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0};
unsigned int count2[nCut2]={0};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i];
//printf("-------------- %ld\n", i);
if( event.size() == 0 ) return;
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();
if( event[k].ch == 6 ) {ch1 = event[k].energy; t1 = event[k].timestamp;} // Reads channel 6 of the digitizer corresponding to dE
if( event[k].ch == 7 ) {ch4 = event[k].energy; t4 = event[k].timestamp;} // Reads channel 7 of the digitizer corresponding to E
if( event[k].ch == 1 ) {ch7 = event[k].energy; t7 = event[k].timestamp;}
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
//hPID->Fill(ch4 , ch1); // x, y
//etotal = ch1*0.25*0.25 + ch4
hdE->Fill(ch1);
hE->Fill(ch4);
hdT->Fill(ch7);
hTotE->Fill(ch1*0.25*0.25 + ch4);
hdEE->Fill(ch4,ch1);
hdEtotE->Fill(ch1*0.25*0.25 + ch4,ch1);
hdEdT->Fill((t7-t1)*1e9,ch1);
hTWin->Fill((t4-t1)*1e9);
//check events inside any Graphical cut and extract the rate
/*
for(int p = 0; p < cutList.count(); p++ ){
if( cutList[p].isEmpty() ) continue;
if( cutList[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin[p] ) tMin[p] = t1;
if( t1 > tMax[p] ) tMax[p] = t1;
count[p] ++;
//printf(".... %d \n", count[p]);
}
}
*/
for(int p = 0; p < cutList1.count(); p++ ){
if( cutList1[p].isEmpty() ) continue;
if( cutList1[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
if( t1 < tMin1[p] ) tMin1[p] = t1;
if( t1 > tMax1[p] ) tMax1[p] = t1;
count1[p] ++;
//printf("hdEE.... %d \n", count1[p]);
}
}
for(int p = 0; p < cutList2.count(); p++ ){
if( cutList2[p].isEmpty() ) continue;
if( cutList2[p].containsPoint(QPointF(ch1+ch4,ch1), Qt::OddEvenFill) ){
if( t1 < tMin2[p] ) tMin2[p] = t1;
if( t1 > tMax2[p] ) tMax2[p] = t1;
count2[p] ++;
//printf("hdEtotE.... %d \n", count2[p]);
}
}
}
for(int p = 0; p < cutList2.count(); p++ ){
printf("hdEE.... %d %d \n", p, count1[p]);
}
//hPID->UpdatePlot();
hdE->UpdatePlot();
hE->UpdatePlot();
hdT->UpdatePlot();
hTotE->UpdatePlot();
hdEE->UpdatePlot();
hdEtotE->UpdatePlot();
hdEdT->UpdatePlot();
hTWin->UpdatePlot();
/*
//========== output to Influx
QList<QString> cutNameList = hPID->GetCutNameList();
for( int p = 0; p < cutList.count(); p ++){
if( cutList[p].isEmpty() ) continue;
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
double rate = count[p]*1.0/(dT);
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
influx->WriteData(dataBaseName);
influx->ClearDataPointsBuffer();
}
*/
}
#endif

View File

@ -1,8 +1,8 @@
#ifndef MACRO_H
#define MACRO_H
#define MaxNPorts 4 //for optical link
#define MaxNBoards 4 //for both optical link and usb
#define MaxNPorts 1 //for optical link
#define MaxNBoards 2 //for both optical link and usb
#define MaxNDigitizer MaxNPorts * MaxNBoards