From 806a7124a4f3ed5c260fbea21e0f1a77af66902f Mon Sep 17 00:00:00 2001 From: "Ryan@WorkStation" Date: Wed, 20 Mar 2024 18:56:49 -0400 Subject: [PATCH] Move EventBuilder to the DAQ code. in progress of the Webbase Simulation code --- .vscode/settings.json | 6 +- Armory/EventBuilder.cpp | 351 ---------------------------- Armory/Hit.h | 287 ----------------------- Armory/Makefile | 12 - Armory/SolReader.h | 258 -------------------- WebSimHelper/files/.gitkeep | 0 WebSimHelper/heliosmatics.html | 255 ++++++++++---------- WebSimHelper/instruction.html | 16 +- WebSimHelper/montecarlo.js | 113 +++++++++ working/Check_Simulation_Config.txt | 4 +- working/test.C | 49 ++++ 11 files changed, 300 insertions(+), 1051 deletions(-) delete mode 100644 Armory/EventBuilder.cpp delete mode 100644 Armory/Hit.h delete mode 100644 Armory/Makefile delete mode 100644 Armory/SolReader.h create mode 100755 WebSimHelper/files/.gitkeep create mode 100644 WebSimHelper/montecarlo.js create mode 100644 working/test.C diff --git a/.vscode/settings.json b/.vscode/settings.json index 162a9a6..4030e25 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -124,7 +124,11 @@ "script_multi.C": "cpp", "Isotope.C": "cpp", "classisotope.h": "c", - "knockoutSim.C": "cpp" + "knockoutSim.C": "cpp", + "test.C": "cpp", + "SimTransfer.C": "cpp", + "httpaccess.C": "cpp", + "httpcontrol.C": "cpp" }, "better-comments.multilineComments": true, diff --git a/Armory/EventBuilder.cpp b/Armory/EventBuilder.cpp deleted file mode 100644 index 13a0f0f..0000000 --- a/Armory/EventBuilder.cpp +++ /dev/null @@ -1,351 +0,0 @@ -#include "SolReader.h" -#include -#include - -#include "TFile.h" -#include "TTree.h" -#include "TMath.h" -#include "TString.h" -#include "TMacro.h" -//#include "TClonesArray.h" // plan to save trace as TVector with TClonesArray -//#include "TVector.h" - -#define MAX_MULTI 64 -#define MAX_TRACE_LEN 2500 - -#define tick2ns 8 // 1 tick = 8 ns - -SolReader ** reader; -Hit ** hit; - -std::vector> idList; - -unsigned long totFileSize = 0; -unsigned long processedFileSize = 0; - -std::vector activeFileID; -std::vector groupIndex; -std::vector> group; // group[i][j], i = group ID, j = group member) - -void findEarliestTime(int &fileID, int &groupID){ - - unsigned long firstTime = 0; - for( int i = 0; i < (int) activeFileID.size(); i++){ - int id = activeFileID[i]; - if( i == 0 ) { - firstTime = hit[id]->timestamp; - fileID = id; - groupID = i; - //printf("%d | %d %lu %d | %d \n", id, reader[id]->GetBlockID(), hit[id]->timestamp, hit[id]->channel, (int) activeFileID.size()); - continue; - } - if( hit[id]->timestamp <= firstTime) { - firstTime = hit[id]->timestamp; - fileID = id; - groupID = i; - //printf("%d | %d %lu %d | %d \n", id, reader[id]->GetBlockID(), hit[id]->timestamp, hit[id]->channel, (int) activeFileID.size()); - } - } - -} - -unsigned long long evID = 0; -unsigned int multi = 0; -unsigned short bd[MAX_MULTI] = {0}; -unsigned short sn[MAX_MULTI] = {0}; -unsigned short ch[MAX_MULTI] = {0}; -unsigned short e[MAX_MULTI] = {0}; -unsigned short e2[MAX_MULTI] = {0}; //for PSD energy short -unsigned long long e_t[MAX_MULTI] = {0}; -unsigned short e_f[MAX_MULTI] = {0}; -unsigned short lowFlag[MAX_MULTI] = {0}; -unsigned short highFlag[MAX_MULTI] = {0}; -int traceLen[MAX_MULTI] = {0}; -int trace[MAX_MULTI][MAX_TRACE_LEN] = {0}; - -void fillData(int &fileID, const bool &saveTrace){ - bd[multi] = idList[fileID][1]; - sn[multi] = idList[fileID][3]; - ch[multi] = hit[fileID]->channel; - e[multi] = hit[fileID]->energy; - e2[multi] = hit[fileID]->energy_short; - e_t[multi] = hit[fileID]->timestamp; - e_f[multi] = hit[fileID]->fine_timestamp; - lowFlag[multi] = hit[fileID]->flags_low_priority; - highFlag[multi] = hit[fileID]->flags_high_priority; - - if( saveTrace ){ - traceLen[multi] = hit[fileID]->traceLenght; - for( int i = 0; i < TMath::Min(traceLen[multi], MAX_TRACE_LEN); i++){ - trace[multi][i] = hit[fileID]->analog_probes[0][i]; - } - } - - multi++; - reader[fileID]->ReadNextBlock(); -} - -void printEvent(){ - printf("==================== evID : %llu\n", evID); - for( int i = 0; i < multi; i++){ - printf(" %2d | %d %d | %llu %d \n", i, bd[i], ch[i], e_t[i], e[i] ); - } - printf("==========================================\n"); -} - -//^################################################################################## -int main(int argc, char ** argv){ - - printf("=======================================================\n"); - printf("=== SOLARIS Event Builder sol --> root ===\n"); - printf("=======================================================\n"); - - if( argc <= 3){ - printf("%s [outfile] [timeWindow] [saveTrace] [sol-1] [sol-2] ... \n", argv[0]); - printf(" outfile : output root file name\n"); - printf(" timeWindow : number of tick, 1 tick = %d ns.\n", tick2ns); - printf(" saveTrace : 1 = save trace, 0 = no trace\n"); - printf(" sol-X : the sol file(s)\n"); - return -1; - } - - // for( int i = 0; i < argc; i++){ - // printf("%d | %s\n", i, argv[i]); - // } - - TString outFileName = argv[1]; - int timeWindow = abs(atoi(argv[2])); - const bool saveTrace = atoi(argv[3]); - - const int nFile = argc - 4; - TString inFileName[nFile]; - for( int i = 0 ; i < nFile ; i++){ - inFileName[i] = argv[i+4]; - } - - //*======================================== setup reader - reader = new SolReader*[nFile]; - hit = new Hit *[nFile]; - - for( int i = 0 ; i < nFile ; i++){ - reader[i] = new SolReader(inFileName[i].Data()); - hit[i] = reader[i]->hit; //TODO check is file open propertly - reader[i]->ReadNextBlock(); // read the first block - } - - //*======================================== group files - idList.clear(); - for( int i = 0; i < nFile; i++){ - TString fn = inFileName[i]; - - int pos = fn.Last('/'); // path - fn.Remove(0, pos+1); - - pos = fn.First('_'); // expName; - fn.Remove(0, pos+1); - - pos = fn.First('_'); // runNum; - fn.Remove(0, pos+1); - - pos = fn.First('_'); // digiID - TString f1 = fn; - int digiID = f1.Remove(pos).Atoi(); - fn.Remove(0, pos+1); - - pos = fn.Last('_'); // digi serial num - f1 = fn; - int digisn = f1.Remove(pos).Atoi(); - fn.Remove(0, pos+1); - - pos = fn.First('.'); // get the file id; - int indexID = fn.Remove(pos).Atoi(); - - int fileID = i; - std::vector haha = {fileID, digiID, indexID, digisn}; - idList.push_back(haha); - } - - // sort by digiID - std::sort(idList.begin(), idList.end(), [](const std::vector& a, const std::vector& b){ - if (a[1] == b[1]) { - return a[2] < b[2]; - } - return a[1] < b[1]; - }); - - group.clear(); // group[i][j], i is the group Index = digiID - int last_id = 0; - std::vector kaka; - for( int i = 0; i < (int) idList.size() ; i++){ - if( i == 0 ) { - kaka.clear(); - last_id = idList[i][1]; - kaka.push_back(idList[i][0]); - continue; - } - - if( idList[i][1] != last_id ) { - last_id = idList[i][1]; - group.push_back(kaka); - kaka.clear(); - kaka.push_back(idList[i][0]); - }else{ - kaka.push_back(idList[i][0]); - } - } - group.push_back(kaka); - - printf(" out file : \033[1;33m%s\033[m\n", outFileName.Data()); - printf(" Event building time window : %d tics = %d nsec \n", timeWindow, timeWindow*tick2ns); - printf(" Save Trace ? %s \n", saveTrace ? "Yes" : "No"); - printf(" Number of input file : %d \n", nFile); - for( int i = 0; i < nFile; i++){ - printf(" %2d| %5.1f MB| %s \n", i, reader[i]->GetFileSize()/1024./1024., inFileName[i].Data()); - totFileSize += reader[i]->GetFileSize(); - } - printf("------------------------------------\n"); - for( int i = 0; i < (int) group.size(); i++){ - printf("Group %d :", i); - for( int j = 0; j < (int) group[i].size(); j ++){ - printf("%d, ", group[i][j]); - } - printf("\n"); - } - printf("------------------------------------\n"); - - //*======================================== setup tree - TFile * outRootFile = new TFile(outFileName, "recreate"); - outRootFile->cd(); - - TTree * tree = new TTree("tree", outFileName); - - tree->Branch("evID", &evID, "event_ID/l"); - tree->Branch("multi", &multi, "multi/i"); - tree->Branch("bd", bd, "board[multi]/s"); - tree->Branch("sn", sn, "sn[multi]/s"); - tree->Branch("ch", ch, "channel[multi]/s"); - tree->Branch("e", e, "energy[multi]/s"); - tree->Branch("e2", e2, "energy_short[multi]/s"); - tree->Branch("e_t", e_t, "timestamp[multi]/l"); - tree->Branch("e_f", e_f, "fine_timestamp[multi]/s"); - tree->Branch("lowFlag", lowFlag, "lowFlag[multi]/s"); - tree->Branch("highFlag", highFlag, "highFlag[multi]/s"); - - if( saveTrace){ - tree->Branch("tl", traceLen, "traceLen[multi]/I"); - tree->Branch("trace", trace, Form("trace[multi][%d]/I", MAX_TRACE_LEN)); - } - - //*=========================================== build event - - //@---- using file from group[i][0] first - - //--- find earlist time among the files - activeFileID.clear(); - groupIndex.clear(); //the index of each group - - for(int i = 0; i < (int) group.size(); i++) { - groupIndex.push_back(0); - activeFileID.push_back(group[i][0]); - } - - int fileID = 0; - int groupID = 0; - findEarliestTime(fileID, groupID); - fillData(fileID, saveTrace); - - unsigned long firstTimeStamp = hit[fileID]->timestamp; - unsigned long lastTimeStamp = 0; - - int last_precentage = 0; - while((activeFileID.size() > 0)){ - - findEarliestTime(fileID, groupID); - if( reader[fileID]->IsEndOfFile() ){ - groupIndex[groupID] ++; - if( groupIndex[groupID] < (int) group[groupID].size() ){ - activeFileID[groupID] = group[groupID][groupIndex[groupID]]; - fileID = activeFileID[groupID]; - }else{ - activeFileID.erase(activeFileID.begin() + groupID); - } - } - - if( hit[fileID]->timestamp - e_t[0] < timeWindow ){ - fillData(fileID, saveTrace); - }else{ - outRootFile->cd(); - tree->Fill(); - evID ++; - - multi = 0; - fillData(fileID, saveTrace); - } - - ///========= calculate progress - processedFileSize = 0; - for( int p = 0; p < (int) group.size(); p ++){ - for( int q = 0; q <= groupIndex[p]; q++){ - if( groupIndex[p] < (int) group[p].size() ){ - int id = group[p][q]; - processedFileSize += reader[id]->GetFilePos(); - } - } - } - double percentage = processedFileSize * 100/ totFileSize; - if( percentage >= last_precentage ) { - printf("Processed : %llu, %.0f%% | %lu/%lu | ", evID, percentage, processedFileSize, totFileSize); - for( int i = 0; i < (int) activeFileID.size(); i++) printf("%d, ", activeFileID[i]); - printf(" \n\033[A\r"); - last_precentage = percentage + 1.0; - } - }; ///====== end of event building loop - - processedFileSize = 0; - for( int p = 0; p < (int) group.size(); p ++){ - for( int q = 0; q < (int) group[p].size(); q++){ - int id = group[p][q]; - processedFileSize += reader[id]->GetFilePos(); - } - } - double percentage = processedFileSize * 100/ totFileSize; - printf("Processed : %llu, %.0f%% | %lu/%lu \n", evID, percentage, processedFileSize, totFileSize); - - lastTimeStamp = hit[fileID]->timestamp; - //*=========================================== save file - outRootFile->cd(); - tree->Fill(); - evID ++; - tree->Write(); - - //*=========================================== Save timestamp as TMacro - TMacro timeStamp; - TString str; - str.Form("%lu", firstTimeStamp); timeStamp.AddLine( str.Data() ); - str.Form("%lu", lastTimeStamp); timeStamp.AddLine( str.Data() ); - timeStamp.Write("timeStamp"); - - unsigned int numBlock = 0; - for( int i = 0; i < nFile; i++){ - //printf("%d | %8ld | %10u/%10u\n", i, reader[i]->GetBlockID() + 1, reader[i]->GetFilePos(), reader[i]->GetFileSize()); - numBlock += reader[i]->GetBlockID() + 1; - } - - printf("===================================== done. \n"); - printf("Number of Block Scanned : %u\n", numBlock); - printf(" Number of Event Built : %lld\n", evID); - printf(" Output Root File Size : %.2f MB\n", outRootFile->GetSize()/1024./1024.); - printf(" first timestamp : %lu \n", firstTimeStamp); - printf(" last timestamp : %lu \n", lastTimeStamp); - unsigned long duration = lastTimeStamp - firstTimeStamp; - printf(" total duration : %lu = %.2f sec \n", duration, duration * tick2ns * 1.0 / 1e9 ); - printf("===================================== end of summary. \n"); - - - //^############## delete new - for( int i = 0; i < nFile; i++) delete reader[i]; - delete [] reader; - outRootFile->Close(); - - return 0; -} \ No newline at end of file diff --git a/Armory/Hit.h b/Armory/Hit.h deleted file mode 100644 index 1a945b1..0000000 --- a/Armory/Hit.h +++ /dev/null @@ -1,287 +0,0 @@ -#ifndef HIT_H -#define HIT_H - -#include -#include -#include -#include - -#define MaxTraceLenght 8100 - -enum DataFormat{ - - ALL = 0x00, - OneTrace = 0x01, - NoTrace = 0x02, - Minimum = 0x03, - MiniWithFineTime = 0x04, - Raw = 0x0A, - -}; - -namespace DPPType{ - - const std::string PHA = "DPP_PHA"; - const std::string PSD = "DPP_PSD"; - -}; - -class Hit { - public: - - unsigned short dataType; - std::string DPPType; - - ///============= for dpp-pha - uint8_t channel; // 6 bit - uint16_t energy; // 16 bit - uint16_t energy_short; // 16 bit, only for PSD - uint64_t timestamp; // 48 bit - uint16_t fine_timestamp; // 10 bit - uint16_t flags_low_priority; // 12 bit - uint16_t flags_high_priority; // 8 bit - size_t traceLenght; // 64 bit - uint8_t downSampling; // 8 bit - bool board_fail; - bool flush; - uint8_t analog_probes_type[2]; // 3 bit for PHA, 4 bit for PSD - uint8_t digital_probes_type[4]; // 4 bit for PHA, 5 bit for PSD - int32_t * analog_probes[2]; // 18 bit - uint8_t * digital_probes[4]; // 1 bit - uint16_t trigger_threashold; // 16 bit - size_t event_size; // 64 bit - uint32_t aggCounter; // 32 bit - - ///============= for raw - uint8_t * data; - size_t dataSize; /// number of byte of the data, size/8 = word [64 bits] - uint32_t n_events; - - bool isTraceAllZero; - - Hit(){ - Init(); - } - - ~Hit(){ - ClearMemory(); - } - - void Init(){ - DPPType = DPPType::PHA; - dataType = DataFormat::ALL; - - channel = 0; - energy = 0; - energy_short = 0; - timestamp = 0; - fine_timestamp = 0; - downSampling = 0; - board_fail = false; - flush = false; - flags_low_priority = 0; - flags_high_priority = 0; - trigger_threashold = 0; - event_size = 0; - aggCounter = 0; - analog_probes[0] = NULL; - analog_probes[1] = NULL; - digital_probes[0] = NULL; - digital_probes[1] = NULL; - digital_probes[2] = NULL; - digital_probes[3] = NULL; - - analog_probes_type[0] = 0xFF; - analog_probes_type[1] = 0xFF; - digital_probes_type[0] = 0xFF; - digital_probes_type[1] = 0xFF; - digital_probes_type[2] = 0xFF; - digital_probes_type[3] = 0xFF; - data = NULL; - - isTraceAllZero = true; // indicate trace are all zero - } - - void ClearMemory(){ - if( data != NULL ) delete data; - - if( analog_probes[0] != NULL) delete analog_probes[0]; - if( analog_probes[1] != NULL) delete analog_probes[1]; - - if( digital_probes[0] != NULL) delete digital_probes[0]; - if( digital_probes[1] != NULL) delete digital_probes[1]; - if( digital_probes[2] != NULL) delete digital_probes[2]; - if( digital_probes[3] != NULL) delete digital_probes[3]; - - isTraceAllZero = true; - } - - void SetDataType(unsigned int type, std::string dppType){ - dataType = type; - DPPType = dppType; - ClearMemory(); - - if( dataType == DataFormat::Raw){ - data = new uint8_t[20*1024*1024]; - }else{ - analog_probes[0] = new int32_t[MaxTraceLenght]; - analog_probes[1] = new int32_t[MaxTraceLenght]; - - digital_probes[0] = new uint8_t[MaxTraceLenght]; - digital_probes[1] = new uint8_t[MaxTraceLenght]; - digital_probes[2] = new uint8_t[MaxTraceLenght]; - digital_probes[3] = new uint8_t[MaxTraceLenght]; - - isTraceAllZero = true; - - } - } - - void ClearTrace(){ - if( isTraceAllZero ) return; // no need to clear again - - for( int i = 0; i < MaxTraceLenght; i++){ - analog_probes[0][i] = 0; - analog_probes[1][i] = 0; - - digital_probes[0][i] = 0; - digital_probes[1][i] = 0; - digital_probes[2][i] = 0; - digital_probes[3][i] = 0; - } - isTraceAllZero = true; - } - - void PrintEnergyTimeStamp(){ - printf("ch: %2d, energy: %u, timestamp: %lu ch, traceLenght: %lu\n", channel, energy, timestamp, traceLenght); - } - - std::string AnaProbeType(uint8_t probeType){ - - if( DPPType == DPPType::PHA){ - switch(probeType){ - case 0: return "ADC"; - case 1: return "Time filter"; - case 2: return "Energy filter"; - default : return "none"; - } - }else if (DPPType == DPPType::PSD){ - switch(probeType){ - case 0: return "ADC"; - case 9: return "Baseline"; - case 10: return "CFD"; - default : return "none"; - } - }else{ - return "none"; - } - } - - std::string DigiProbeType(uint8_t probeType){ - - if( DPPType == DPPType::PHA){ - switch(probeType){ - case 0: return "Trigger"; - case 1: return "Time filter armed"; - case 2: return "Re-trigger guard"; - case 3: return "Energy filter baseline freeze"; - case 4: return "Energy filter peaking"; - case 5: return "Energy filter peaking ready"; - case 6: return "Energy filter pile-up guard"; - case 7: return "Event pile-up"; - case 8: return "ADC saturation"; - case 9: return "ADC saturation protection"; - case 10: return "Post-saturation event"; - case 11: return "Energy filter saturation"; - case 12: return "Signal inhibit"; - default : return "none"; - } - }else if (DPPType == DPPType::PSD){ - switch(probeType){ - case 0: return "Trigger"; - case 1: return "CFD Filter Armed"; - case 2: return "Re-trigger guard"; - case 3: return "ADC Input Baseline freeze"; - case 20: return "ADC Input OverThreshold"; - case 21: return "Charge Ready"; - case 22: return "Long Gate"; - case 7: return "Pile-Up Trig."; - case 24: return "Short Gate"; - case 25: return "Energy Saturation"; - case 26: return "Charge over-range"; - case 27: return "ADC Input Neg. OverThreshold"; - default : return "none"; - } - - }else{ - return "none"; - } - } - - std::string HighPriority(uint16_t prio){ - std::string output; - - bool pileup = prio & 0x1; - //bool pileupGuard = (prio >> 1) & 0x1; - //bool eventSaturated = (prio >> 2) & 0x1; - //bool postSatEvent = (prio >> 3) & 0x1; - //bool trapSatEvent = (prio >> 4) & 0x1; - //bool SCA_Event = (prio >> 5) & 0x1; - - output = std::string("Pile-up: ") + (pileup ? "Yes" : "No"); - - return output; - } - - //TODO LowPriority - - void PrintAll(){ - - switch(dataType){ - case DataFormat::ALL : printf("============= Type : ALL\n"); break; - case DataFormat::OneTrace : printf("============= Type : OneTrace\n"); break; - case DataFormat::NoTrace : printf("============= Type : NoTrace\n"); break; - case DataFormat::MiniWithFineTime : printf("============= Type : Min with FineTimestamp\n"); break; - case DataFormat::Minimum : printf("============= Type : Minimum\n"); break; - case DataFormat::Raw : printf("============= Type : Raw\n"); return; break; - default : return; - } - - printf("ch : %2d (0x%02X), fail: %d, flush: %d\n", channel, channel, board_fail, flush); - if( DPPType == DPPType::PHA ) printf("energy: %u, timestamp: %lu, fine_timestamp: %u \n", energy, timestamp, fine_timestamp); - if( DPPType == DPPType::PSD ) printf("energy: %u, energy_S : %u, timestamp: %lu, fine_timestamp: %u \n", energy, energy_short, timestamp, fine_timestamp); - printf("flag (high): 0x%02X, (low): 0x%03X, traceLength: %lu\n", flags_high_priority, flags_low_priority, traceLenght); - printf("Agg counter : %u, trigger Thr.: %u, downSampling: %u \n", aggCounter, trigger_threashold, downSampling); - printf("AnaProbe Type: %s(%u), %s(%u)\n", AnaProbeType(analog_probes_type[0]).c_str(), analog_probes_type[0], - AnaProbeType(analog_probes_type[1]).c_str(), analog_probes_type[1]); - printf("DigProbe Type: %s(%u), %s(%u), %s(%u), %s(%u)\n", DigiProbeType(digital_probes_type[0]).c_str(), digital_probes_type[0], - DigiProbeType(digital_probes_type[1]).c_str(), digital_probes_type[1], - DigiProbeType(digital_probes_type[2]).c_str(), digital_probes_type[2], - DigiProbeType(digital_probes_type[3]).c_str(), digital_probes_type[3]); - } - - void PrintTrace(unsigned short ID){ - for(unsigned short i = 0; i < (unsigned short)traceLenght; i++){ - if( ID == 0 ) printf("%4d| %6d\n", i, analog_probes[0][i]); - if( ID == 1 ) printf("%4d| %6d\n", i, analog_probes[1][i]); - if( ID == 2 ) printf("%4d| %u\n", i, digital_probes[0][i]); - if( ID == 3 ) printf("%4d| %u\n", i, digital_probes[1][i]); - if( ID == 4 ) printf("%4d| %u\n", i, digital_probes[2][i]); - if( ID == 5 ) printf("%4d| %u\n", i, digital_probes[3][i]); - } - } - - void PrintAllTrace(){ - for(unsigned short i = 0; i < (unsigned short)traceLenght; i++){ - printf("%4d| %6d %6d %1d %1d %1d %1d\n", i, analog_probes[0][i], - analog_probes[1][i], - digital_probes[0][i], - digital_probes[1][i], - digital_probes[2][i], - digital_probes[3][i]); - } - } - -}; - -#endif \ No newline at end of file diff --git a/Armory/Makefile b/Armory/Makefile deleted file mode 100644 index 4de3a66..0000000 --- a/Armory/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -CC=g++ -CFLAG= -g -ROOTFLAG=`root-config --cflags --glibs` - -all: EventBuilder - -EventBuilder: EventBuilder.cpp SolReader.h Hit.h - $(CC) $(CFLAG) EventBuilder.cpp -o EventBuilder ${ROOTFLAG} - - -clean: - -rm EventBuilder \ No newline at end of file diff --git a/Armory/SolReader.h b/Armory/SolReader.h deleted file mode 100644 index 8761666..0000000 --- a/Armory/SolReader.h +++ /dev/null @@ -1,258 +0,0 @@ -#ifndef SOLREADER_H -#define SOLREADER_H - -#include /// for FILE -#include -#include -#include -#include -#include // time in nano-sec - -#include "Hit.h" - -class SolReader { - private: - FILE * inFile; - unsigned int inFileSize; - unsigned int filePos; - unsigned int totNumBlock; - - unsigned short blockStartIdentifier; - unsigned int numBlock; - bool isScanned; - - void init(); - - std::vector blockPos; - - public: - SolReader(); - SolReader(std::string fileName, unsigned short dataType); - ~SolReader(); - - void OpenFile(std::string fileName); - int ReadNextBlock(int isSkip = 0); // opt = 0, noraml, 1, fast - int ReadBlock(unsigned int index, bool verbose = false); - - void ScanNumBlock(); - - bool IsEndOfFile() const {return (filePos >= inFileSize ? true : false);} - unsigned int GetBlockID() const {return numBlock - 1;} - unsigned int GetNumBlock() const {return numBlock;} - unsigned int GetTotalNumBlock() const {return totNumBlock;} - unsigned int GetFilePos() const {return filePos;} - unsigned int GetFileSize() const {return inFileSize;} - - void RewindFile(); - - Hit * hit; - -}; - -void SolReader::init(){ - inFileSize = 0; - numBlock = 0; - filePos = 0; - totNumBlock = 0; - hit = new Hit(); - - isScanned = false; - - blockPos.clear(); - -} - -SolReader::SolReader(){ - init(); -} - -SolReader::SolReader(std::string fileName, unsigned short dataType = 0){ - init(); - OpenFile(fileName); - hit->SetDataType(dataType, DPPType::PHA); -} - -SolReader::~SolReader(){ - if( !inFile ) fclose(inFile); - delete hit; -} - -inline void SolReader::OpenFile(std::string fileName){ - inFile = fopen(fileName.c_str(), "r"); - if( inFile == NULL ){ - printf("Cannot open file : %s \n", fileName.c_str()); - }else{ - fseek(inFile, 0L, SEEK_END); - inFileSize = ftell(inFile); - rewind(inFile); - } -} - -inline int SolReader::ReadBlock(unsigned int index, bool verbose){ - if( isScanned == false) return -1; - if( index >= totNumBlock )return -1; - fseek(inFile, 0L, SEEK_SET); - - if( verbose ) printf("Block index: %u, File Pos: %u byte\n", index, blockPos[index]); - - fseek(inFile, blockPos[index], SEEK_CUR); - - filePos = blockPos[index]; - - numBlock = index; - - return ReadNextBlock(); -} - -inline int SolReader::ReadNextBlock(int isSkip){ - if( inFile == NULL ) return -1; - if( feof(inFile) ) return -1; - if( filePos >= inFileSize) return -1; - - fread(&blockStartIdentifier, 2, 1, inFile); - - if( (blockStartIdentifier & 0xAA00) != 0xAA00 ) { - printf("header fail.\n"); - return -2 ; - } - - if( ( blockStartIdentifier & 0xF ) == DataFormat::Raw ){ - hit->SetDataType(DataFormat::Raw, ((blockStartIdentifier >> 1) & 0xF) == 0 ? DPPType::PHA : DPPType::PSD); - } - hit->dataType = blockStartIdentifier & 0xF; - hit->DPPType = ((blockStartIdentifier >> 4) & 0xF) == 0 ? DPPType::PHA : DPPType::PSD; - - if( hit->dataType == DataFormat::ALL){ - if( isSkip == 0 ){ - fread(&hit->channel, 1, 1, inFile); - fread(&hit->energy, 2, 1, inFile); - if( hit->DPPType == DPPType::PSD ) fread(&hit->energy_short, 2, 1, inFile); - fread(&hit->timestamp, 6, 1, inFile); - fread(&hit->fine_timestamp, 2, 1, inFile); - fread(&hit->flags_high_priority, 1, 1, inFile); - fread(&hit->flags_low_priority, 2, 1, inFile); - fread(&hit->downSampling, 1, 1, inFile); - fread(&hit->board_fail, 1, 1, inFile); - fread(&hit->flush, 1, 1, inFile); - fread(&hit->trigger_threashold, 2, 1, inFile); - fread(&hit->event_size, 8, 1, inFile); - fread(&hit->aggCounter, 4, 1, inFile); - }else{ - fseek(inFile, hit->DPPType == DPPType::PHA ? 31 : 33, SEEK_CUR); - } - fread(&hit->traceLenght, 8, 1, inFile); - if( isSkip == 0){ - fread(hit->analog_probes_type, 2, 1, inFile); - fread(hit->digital_probes_type, 4, 1, inFile); - fread(hit->analog_probes[0], hit->traceLenght*4, 1, inFile); - fread(hit->analog_probes[1], hit->traceLenght*4, 1, inFile); - fread(hit->digital_probes[0], hit->traceLenght, 1, inFile); - fread(hit->digital_probes[1], hit->traceLenght, 1, inFile); - fread(hit->digital_probes[2], hit->traceLenght, 1, inFile); - fread(hit->digital_probes[3], hit->traceLenght, 1, inFile); - }else{ - fseek(inFile, 6 + hit->traceLenght*(12), SEEK_CUR); - } - - }else if( hit->dataType == DataFormat::OneTrace){ - if( isSkip == 0 ){ - fread(&hit->channel, 1, 1, inFile); - fread(&hit->energy, 2, 1, inFile); - if( hit->DPPType == DPPType::PSD ) fread(&hit->energy_short, 2, 1, inFile); - fread(&hit->timestamp, 6, 1, inFile); - fread(&hit->fine_timestamp, 2, 1, inFile); - fread(&hit->flags_high_priority, 1, 1, inFile); - fread(&hit->flags_low_priority, 2, 1, inFile); - }else{ - fseek(inFile, hit->DPPType == DPPType::PHA ? 14 : 16, SEEK_CUR); - } - fread(&hit->traceLenght, 8, 1, inFile); - if( isSkip == 0){ - fread(&hit->analog_probes_type[0], 1, 1, inFile); - fread(hit->analog_probes[0], hit->traceLenght*4, 1, inFile); - }else{ - fseek(inFile, 1 + hit->traceLenght*4, SEEK_CUR); - } - - }else if( hit->dataType == DataFormat::NoTrace){ - if( isSkip == 0 ){ - fread(&hit->channel, 1, 1, inFile); - fread(&hit->energy, 2, 1, inFile); - if( hit->DPPType == DPPType::PSD ) fread(&hit->energy_short, 2, 1, inFile); - fread(&hit->timestamp, 6, 1, inFile); - fread(&hit->fine_timestamp, 2, 1, inFile); - fread(&hit->flags_high_priority, 1, 1, inFile); - fread(&hit->flags_low_priority, 2, 1, inFile); - }else{ - fseek(inFile, hit->DPPType == DPPType::PHA ? 14 : 16, SEEK_CUR); - } - - }else if( hit->dataType == DataFormat::MiniWithFineTime){ - if( isSkip == 0 ){ - fread(&hit->channel, 1, 1, inFile); - fread(&hit->energy, 2, 1, inFile); - if( hit->DPPType == DPPType::PSD ) fread(&hit->energy_short, 2, 1, inFile); - fread(&hit->timestamp, 6, 1, inFile); - fread(&hit->fine_timestamp, 2, 1, inFile); - }else{ - fseek(inFile, hit->DPPType == DPPType::PHA ? 11 : 13, SEEK_CUR); - } - - }else if( hit->dataType == DataFormat::Minimum){ - if( isSkip == 0 ){ - fread(&hit->channel, 1, 1, inFile); - fread(&hit->energy, 2, 1, inFile); - if( hit->DPPType == DPPType::PSD ) fread(&hit->energy_short, 2, 1, inFile); - fread(&hit->timestamp, 6, 1, inFile); - }else{ - fseek(inFile, hit->DPPType == DPPType::PHA ? 9 : 11, SEEK_CUR); - } - - }else if( hit->dataType == DataFormat::Raw){ - fread(&hit->dataSize, 8, 1, inFile); - if( isSkip == 0){ - fread(hit->data, hit->dataSize, 1, inFile); - }else{ - fseek(inFile, hit->dataSize, SEEK_CUR); - } - } - - numBlock ++; - filePos = ftell(inFile); - return 0; -} - -void SolReader::RewindFile(){ - rewind(inFile); - filePos = 0; - numBlock = 0; -} - -void SolReader::ScanNumBlock(){ - if( inFile == NULL ) return; - if( feof(inFile) ) return; - - numBlock = 0; - blockPos.clear(); - - blockPos.push_back(0); - - while( ReadNextBlock(1) == 0){ - blockPos.push_back(filePos); - printf("%u, %.2f%% %u/%u\n\033[A\r", numBlock, filePos*100./inFileSize, filePos, inFileSize); - } - - totNumBlock = numBlock; - numBlock = 0; - isScanned = true; - printf("\nScan complete: number of data Block : %u\n", totNumBlock); - rewind(inFile); - filePos = 0; - - //for( int i = 0; i < totNumBlock; i++){ - // printf("%7d | %u \n", i, blockPos[i]); - //} - -} - -#endif \ No newline at end of file diff --git a/WebSimHelper/files/.gitkeep b/WebSimHelper/files/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/WebSimHelper/heliosmatics.html b/WebSimHelper/heliosmatics.html index 57774d5..b911c74 100644 --- a/WebSimHelper/heliosmatics.html +++ b/WebSimHelper/heliosmatics.html @@ -289,8 +289,130 @@

-
+ +

DWBA & Monte Carlo Simultion

+

DWBA and Ex List:

+For 2-nucleon transfer, Orbital take the form NL=X, where N is number of node, X is momentum number. n and L are related by Σi (2ni+li) = 2N + X + 2n + l, where ni and li are the principle number and orbital angular momentum of the each transfered nucleon, and n and l are the internal quanta of the 2-nucleon. e.g. (t,p) reaction to 0f orbtial, the left-hand side would be ni = 0 and li = 3 and the sum is 3+3 = 6 = 2N + X + 2n+l. Assume n = l = 0, we have 6 = 2N+L. Thus, 3L=0, 2L=2,1L=4, 0L=6.

+ +Beam Jπ: +
TODO: guess the orbital for Beam Jπ=0 +
+Positive parity +Negative parity +Unknown parity +
+ + +Max Ex: MeV + +

+ + + + + + + + + + + + + + + +
Ex [MeV]    Jπ Orbital
+ +

+Cal. DWBA + + + + + + + + +
Incoming Channel + + +
Outgoing Channel + + +
+ + + + Only DWBA and Don't Sim. Angle range (for only DWBA) + + + + + + + +
Min [deg]: Max [deg]:
+ + + + + +

θCM Calculator

The calculation only give θCM after the bending. @@ -323,94 +445,6 @@ The calculation only give θCM after the bending. - - - -

HELIOSmatics was first built by Ben P. Kay in MS Excel around 2010. It was modified by Ryan Tang later. And now it migrated to the web on Dec, 2022. @@ -419,52 +453,11 @@ The calculation can be found in the source code (heliosmatics.js or press F12)

- - - - + diff --git a/WebSimHelper/instruction.html b/WebSimHelper/instruction.html index a5d3dd3..0231ab9 100644 --- a/WebSimHelper/instruction.html +++ b/WebSimHelper/instruction.html @@ -2,15 +2,13 @@