can get data in list mode. need to check the trace data

This commit is contained in:
Ryan Tang 2022-03-04 13:42:24 -05:00
parent c9a353857d
commit 9b03a78cec
10 changed files with 436 additions and 195 deletions

View File

@ -30,7 +30,7 @@ public:
int QDCsum[8];
unsigned long long eventID;
unsigned short trace[1024];
unsigned short trace[4000];
DataBlock(){
Clear();

View File

@ -36,7 +36,7 @@ example.o : example.cpp
$(CC) $(CFLAGS) $(INCFLAGS) example.cpp
test : test.o Pixie16Class.o
$(CC) $(INCFLAGS) test.o Pixie16Class.o $(LIBS) -o test
$(CC) $(INCFLAGS) test.o Pixie16Class.o $(LIBS) -o test $(ROOT_FLAG)
test.o : test.cpp
$(CC) $(CFLAGS) $(INCFLAGS) test.cpp $(ROOT_FLAG)

View File

@ -1,12 +1,13 @@
#ifndef PIXIE16_CPP
#define PIXIE16_CPP
#include "pixie16/pixie16.h"
//#include "pixie16app_export.h"
//#include "pixie16sys_export.h"
//#include "def21160.h"
#include <bitset>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <stdio.h>
@ -51,6 +52,7 @@ Pixie16::Pixie16(){
Statistics = NULL;
data = new DataBlock();
nextWord = 0;
}
}
@ -219,17 +221,37 @@ void Pixie16::BootDigitizers(){
}
void Pixie16::AdjustOffset(){
retval = Pixie16AdjustOffsets(NumModules);
if( CheckError("Pixie16AdjustOffsets") < 0 ) return;
printf(" Adjust Offset for All modules.\n");
}
void Pixie16::StartRun(bool listMode){
unsigned short mode = NEW_RUN; //RESUME_RUN
for( int i = 0 ; i < NumModules; i++){
retval = Pixie16StartListModeRun(i, 0x100, mode);
if( CheckError("Pixie16StartListModeRun") < 0 ) return;
printf("\033[32mModule-%d run\033[0m\n", i);
//listmode
if( listMode ){
isRunning = true;
//SetDigitizerSynchWait(1, i);
//SetDigitizerInSynch(0, i);
retval = Pixie16StartListModeRun(NumModules, LIST_MODE_RUN, mode);
if( CheckError("Pixie16StartListModeRun") < 0 ) return;
printf("\033[32m LIST_MODE run\033[0m\n");
}else{
//MCA mode
retval = Pixie16StartHistogramRun(NumModules, mode);
if( CheckError("Pixie16StartHistogramRun") < 0 ) return;
printf("\033[32m MCA MODE run\033[0m\n");
}
isRunning = true;
}
@ -247,47 +269,75 @@ void Pixie16::StopRun(){
void Pixie16::ReadData(unsigned short modID){
retval = Pixie16CheckExternalFIFOStatus (&nFIFOWords, modID);
if( Pixie16CheckRunStatus(modID) == 1){
unsigned int oldnFIFOWords = nFIFOWords;
retval = Pixie16CheckExternalFIFOStatus (&nFIFOWords, modID);
if( CheckError("Pixie16CheckExternalFIFOStatus") < 0 ) return;
if(nFIFOWords *1.0 / EXTERNAL_FIFO_LENGTH > 0.2) {
//if(nFIFOWords > 0) {
printf("\033[1;31m####### READ DATA \033[m: number of word in module-%d FIFO : %d \n", modID, nFIFOWords);
if( ExtFIFO_Data != NULL ) delete ExtFIFO_Data;
ExtFIFO_Data = new unsigned int [nFIFOWords];
retval = Pixie16ReadDataFromExternalFIFO(ExtFIFO_Data, nFIFOWords, modID);
CheckError("Pixie16ReadDataFromExternalFIFO");
nextWord = nextWord - oldnFIFOWords;
}
}else{
printf("Pixie16 is not running.\n");
}
}
printf("number of word in module-%d FIFO : %d \n", modID, nFIFOWords);
if(nFIFOWords > 0) {
if( ExtFIFO_Data != NULL ) delete ExtFIFO_Data;
ExtFIFO_Data = new unsigned int [nFIFOWords];
retval = Pixie16ReadDataFromExternalFIFO(ExtFIFO_Data, nFIFOWords, modID);
if( CheckError("Pixie16ReadDataFromExternalFIFO") < 0 ) return;
void Pixie16::ProcessSingleData(){
if( nextWord < nFIFOWords ){
data->ch = ExtFIFO_Data[nextWord] & 0xF ;
data->slot = (ExtFIFO_Data[nextWord] >> 4) & 0xF;
data->crate = (ExtFIFO_Data[nextWord] >> 8) & 0xF;
data->headerLength = (ExtFIFO_Data[nextWord] >> 12) & 0x1F;
data->eventLength = (ExtFIFO_Data[nextWord] >> 17) & 0x3FFF;
data->pileup = ExtFIFO_Data[nextWord] >> 31 ;
data->eventID ++;
if( nextWord + data->eventLength < nFIFOWords ){
data->time = ((unsigned long long)(ExtFIFO_Data[nextWord+2] & 0xFFFF) << 32) + ExtFIFO_Data[nextWord+1];
data->cfd = ExtFIFO_Data[nextWord + 2] >> 16 ;
data->energy = (ExtFIFO_Data[nextWord + 3] & 0xFFFF );
data->trace_length = (ExtFIFO_Data[nextWord + 3] >> 16) & 0x7FFF;
data->trace_out_of_range = ExtFIFO_Data[nextWord + 3] >> 31;
if( data->eventLength > data->headerLength ){
for( int i = 0; i < data->trace_length/2 ; i++){
data->trace[2*i+0] = ExtFIFO_Data[nextWord + data->headerLength + i] & 0xFFFF ;
data->trace[2*i+1] = (ExtFIFO_Data[nextWord + data->headerLength + i] >> 16 ) & 0xFFFF ;
}
}else{
data->ClearTrace();
}
}else{
data->time = 0;
data->cfd = 0;
data->energy = 0;
data->trace_length = 0;
data->trace_out_of_range = 0;
}
nextWord += data->eventLength ;
}
}
void Pixie16::PrintData(){
printf("----------------------------\n");
printf("number of words read : %d \n", nFIFOWords);
unsigned int word = 0;
void Pixie16::ProcessData(int verbose){
for( unsigned int i = 0; i < nFIFOWords; i++) printf("%5d|%X|\n", i, ExtFIFO_Data[word]);
if( verbose >= 2 ) for( unsigned int i = 0; i < nFIFOWords; i++) printf("%5d|%X|\n", i, ExtFIFO_Data[nextWord+i]);
while( word < nFIFOWords ){
data->ch = ExtFIFO_Data[word] & 0xF ;
data->slot = (ExtFIFO_Data[word] >> 4) & 0xF;
data->crate = (ExtFIFO_Data[word] >> 8) & 0xF;
data->headerLength = (ExtFIFO_Data[word] >> 12) & 0x1F;
data->eventLength = (ExtFIFO_Data[word] >> 17) & 0x3FFF;
data->pileup = ExtFIFO_Data[word] >> 31 ;
data->time = ((unsigned long long)(ExtFIFO_Data[word+2] & 0xFFFF) << 32) + ExtFIFO_Data[word+1];
data->cfd = ExtFIFO_Data[word + 2] >> 16 ;
data->energy = (ExtFIFO_Data[word + 3] & 0xFFFF );
data->trace_length = (ExtFIFO_Data[word + 3] >> 16) & 0x7FFF;
data->trace_out_of_range = ExtFIFO_Data[word + 3] >> 31;
data->Print(0);
data->eventID ++;
word += data->eventLength + 1;
while( nextWord < nFIFOWords ){
ProcessSingleData();
if( verbose >= 1 ) data->Print(0);
if( verbose >= 3 ) data->Print(1); /// print trace
}
}
void Pixie16::GetTrace(unsigned short modID, unsigned short ch){
@ -322,34 +372,78 @@ void Pixie16::GetBaseLines(unsigned short modID, unsigned short ch){
}
void Pixie16::GetDigitizerSettings(unsigned short modID){
printf("=========== Digitizer setting for module-%d\n", modID);
unsigned int Pixie16::GetDigitizerSetting(std::string parName, unsigned short modID, bool verbose){
unsigned int ParData;
retval = Pixie16ReadSglModPar ((char *)"MODULE_NUMBER", &ParData, modID); printf(" module number: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"CrateID", &ParData, modID); printf(" Crate modID: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"SlotID", &ParData, modID); printf(" Slot modID: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"ModID", &ParData, modID); printf(" Mod modID: %d \n", ParData);
///retval = Pixie16ReadSglModPar ((char *)"MODULE_CSRA", &ParData, modID); printf("channel control registor A: %X \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"MODULE_CSRB", &ParData, modID); printf("channel control registor B: %X \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"MODULE_FORMAT", &ParData, modID); printf(" format: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"MAX_EVENTS", &ParData, modID); printf(" max events: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"SYNCH_WAIT", &ParData, modID); printf(" syn ch wait: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"IN_SYNCH", &ParData, modID); printf(" in syn ch: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"SLOW_FILTER_RANGE", &ParData, modID); printf(" slow filter range: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"FAST_FILTER_RANGE", &ParData, modID); printf(" fast filter range: %d \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"FastTrigBackplaneEna", &ParData, modID); printf("fast trig Backplane enable: %X \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"TrigConfig0", &ParData, modID); printf(" Trig config 0: %X \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"TrigConfig1", &ParData, modID); printf(" Trig config 1: %X \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"TrigConfig2", &ParData, modID); printf(" Trig config 2: %X \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"TrigConfig3", &ParData, modID); printf(" Trig config 3: %X \n", ParData);
retval = Pixie16ReadSglModPar ((char *)"HOST_RT_PRESET", &ParData, modID); printf(" Host run time preset: %d \n", ParData);
retval = Pixie16ReadSglModPar (const_cast<char*> (parName.c_str()), &ParData, modID);
if( CheckError("Pixie16ReadSglModPar::"+parName) < 0 ) return -404;
if( CheckError("GetDigitizerSettings") < 0 ) return;
if( verbose ){
if( parName == "MODULE_CSRA" || parName == "FastTrigBackplaneEna" || parName == "TrigConfig0" || parName == "TrigConfig1" || parName == "TrigConfig2" || parName == "TrigConfig3" ){
printf("READ | Mod : %2d, %20s = %X\n", modID, parName.c_str(), ParData);
}else if(parName == "MODULE_CSRB"){
printf("READ | Mod : %2d, %20s = %X\n", modID, parName.c_str(), ParData);
printf("---------------------------------------------------------------------------\n");
printf( " 32 28 24 20 16 12 8 4 0\n");
printf( " | | | | | | | | |\n");
std::cout <<" Module Configuration : 0xb" << std::bitset<32>(ParData) << std::endl;
printf(" wired-OR trigger lines to backplane to pullup resistor (bit: 0) : %s \n", ParData & MOD_CSRB_BIT::WIRED_OR_TRIGGER_TO_PULLUP_RESIST ? "Yes" : "No");
printf(" Direct module (bit: 4) : %s \n", ParData & MOD_CSRB_BIT::DIRECT_MODULUE ? "Yes" : "No");
printf(" Chassis Master module (bit: 6) : %s \n", ParData & MOD_CSRB_BIT::CHASSIS_MASTER ? "\033[1;33mYes\033[m" : "\033[1;31mNo\033[m");
printf(" Use Global Fast Trigger Source (bit: 7) : %s \n", ParData & MOD_CSRB_BIT::GLOBAL_FAST_TRIGGER ? "Yes" : "No");
printf(" Use external trigger source (bit: 8) : %s \n", ParData & MOD_CSRB_BIT::EXTERNAL_TRIGGER ? "Yes" : "No");
printf(" Control external INHIBIT signal (bit: 10) : %s \n", ParData & MOD_CSRB_BIT::USE_INHIBIT ? "INHIBIT" : "not INHIBIT");
printf(" distribute clock and triggers in multiple crates (bit: 11) : %s \n", ParData & MOD_CSRB_BIT::DISTRIBUTE_CLOCK ? "multiple crates" : "single crate");
printf(" Sort Timestamp (bit: 12) : %s \n", ParData & MOD_CSRB_BIT::SORT_TIMESTAMP ? "\033[1;33mYes\033[m" : "\033[1;31mNo\033[m");
printf(" Enable connection of fast triggers to backplane (bit: 13) : %s \n", ParData & MOD_CSRB_BIT::FAST_TRIGGER_TO_BACKPLANE ? "enable" : "disable");
printf("---------------------------------------------------------------------------\n");
}else if(parName == "SYNCH_WAIT"){
printf("READ | Mod : %2d, %20s = %d (%s)\n", modID, parName.c_str(), ParData, ParData ? "simultaneously" : "not simultaneously");
}else if(parName == "IN_SYNCH"){
printf("READ | Mod : %2d, %20s = %d (%s)\n", modID, parName.c_str(), ParData, ParData ? "not simultaneously" : "simultaneously");
}else if(parName == "HOST_RT_PRESET"){
printf("READ | Mod : %2d, %20s = %f sec\n", modID, parName.c_str(), IEEEFloating2Decimal(ParData));
}else{
printf("READ | Mod : %2d, %20s = %d\n", modID, parName.c_str(), ParData);
}
}
return ParData;
}
void Pixie16::PrintDigitizerSettings(unsigned short modID){
printf("############################################### Digitizer setting for module-%d\n", modID);
///GetDigitizerSetting("MODULE_NUMBER", modID, true);
///GetDigitizerSetting("ModID", modID, true);
///GetDigitizerSetting("MODULE_FORMAT", modID, true);
///GetDigitizerSetting("MODULE_CSRA", modID, true);
///GetDigitizerSetting("MAX_EVENTS", modID, true);
GetDigitizerSetting("CrateID", modID, true);
GetDigitizerSetting("SlotID", modID, true);
GetDigitizerSetting("SYNCH_WAIT", modID, true);
GetDigitizerSetting("IN_SYNCH", modID, true);
GetDigitizerSetting("SLOW_FILTER_RANGE", modID, true);
GetDigitizerSetting("FAST_FILTER_RANGE", modID, true);
GetDigitizerSetting("FastTrigBackplaneEna", modID, true);
GetDigitizerSetting("TrigConfig0", modID, true);
GetDigitizerSetting("TrigConfig1", modID, true);
GetDigitizerSetting("TrigConfig2", modID, true);
GetDigitizerSetting("TrigConfig3", modID, true);
GetDigitizerSetting("HOST_RT_PRESET", modID, true);
GetDigitizerSetting("MODULE_CSRB", modID, true);
}
void Pixie16::SetDigitizerSetting(std::string parName, unsigned int val, unsigned short modID, bool verbose){
retval = Pixie16WriteSglModPar( const_cast<char*> (parName.c_str()), val, modID);
if( CheckError("Pixie16WriteSglModPar::"+parName) < 0 ) return;
if( verbose ) GetDigitizerSetting(parName, modID, verbose);
}
double Pixie16::GetChannelSetting(std::string parName, unsigned short modID, unsigned short ch, bool verbose){
double ParData;
@ -364,14 +458,14 @@ double Pixie16::GetChannelSetting(std::string parName, unsigned short modID, uns
}else if( parName == "BLCUT" ) {
printf("READ | Mod : %2d, CH: %2d, %18s = %5d \n", modID, ch, parName.c_str(), (int) ParData);
}else if ( parName == "CHANNEL_CSRA" || parName == "CHANNEL_CSRB" || parName == "MultiplicityMaskL" || parName == "MultiplicityMaskH"){
if( parName == "CHANNEL_CSRA" ) printf("---------------------------------------------------------------------------\n");
printf("READ | Mod : %2d, CH: %2d, %18s = %X\n", modID, ch, parName.c_str(), (int) ParData);
printf( " 32 28 24 20 16 12 8 4 0\n");
printf( " | | | | | | | | |\n");
std::cout <<" Module Configuration : 0xb" << std::bitset<32>(ParData) << std::endl;
std::cout <<" Channel Configuration : 0xb" << std::bitset<32>(ParData) << std::endl;
if( parName == "CHANNEL_CSRA" ){
int CSRA = (int) ParData;
printf("---------------------------------------------------------------------------\n");
printf(" fast trigger selection (bit: 0) : %s \n", CSRA & CSRA_BIT::FAST_TRIGGER ? "external" : "internal");
printf(" module validation signal selection (bit: 1) : %s \n", CSRA & CSRA_BIT::M_VALIDATION ? "module gate" : "global gate");
printf(" channel enable (bit: 2) : %s \n", CSRA & CSRA_BIT::ENABLE_CHANNEL ? "\033[1;33mYes\033[m" : "\033[1;31mNo\033[m");
@ -418,7 +512,7 @@ unsigned short Pixie16::GetCSRA(int bitwise, unsigned short modID, unsigned sho
void Pixie16::PrintChannelAllSettings(unsigned short modID, unsigned short ch){
printf("===================== Channel setting. Mod-%d CH-%02d\n", modID, ch);
printf("######################################################## Channel setting. Mod-%d CH-%02d\n", modID, ch);
GetChannelSetting("TRIGGER_RISETIME", modID, ch, true);
GetChannelSetting("TRIGGER_FLATTOP", modID, ch, true);
GetChannelSetting("TRIGGER_THRESHOLD", modID, ch, true);
@ -433,7 +527,6 @@ void Pixie16::PrintChannelAllSettings(unsigned short modID, unsigned short ch){
GetChannelSetting("BASELINE_AVERAGE", modID, ch, true);
GetChannelSetting("BLCUT", modID, ch, true);
GetChannelSetting("EMIN", modID, ch, true);
GetChannelSetting("CHANNEL_CSRA", modID, ch, true);
///GetChannelSetting("CHANNEL_CSRB", modID, ch, true); //CSRB is reserved to be zero
GetChannelSetting("QDCLen0", modID, ch, true);
GetChannelSetting("QDCLen1", modID, ch, true);
@ -445,19 +538,22 @@ void Pixie16::PrintChannelAllSettings(unsigned short modID, unsigned short ch){
GetChannelSetting("QDCLen7", modID, ch, true);
GetChannelSetting("MultiplicityMaskL", modID, ch, true);
GetChannelSetting("MultiplicityMaskH", modID, ch, true);
GetChannelSetting("CHANNEL_CSRA", modID, ch, true);
printf("=====================================\n");
}
void Pixie16::PrintChannelsMainSettings(unsigned short modID){
printf(" ch | En | Trig_L | Trig_G | Threshold | Energy_L | Energy_G | Tau | Trace | Trace_d | Voff | BL \n");
printf("----+-----+--------+--------+-----------+----------+----------+-------+------ -+---------+------+------ \n");
printf("====+=====+========+========+===========+==========+==========+==========+========+========+=========+======+====== \n");
printf(" ch | En | Trig_L | Trig_G | Threshold | Polarity | Energy_L | Energy_G | Tau | Trace | Trace_d | Voff | BL \n");
printf("----+-----+--------+--------+-----------+----------+----------+----------+--------+--------+---------+------+------ \n");
for( int ch = 0; ch < 16; ch ++){
printf(" %2d |", ch);
printf(" %3s |", GetChannleOnOff(modID, ch) ? "On" : "Off" );
printf(" %6.2f |", GetChannelTriggerRiseTime(modID, ch));
printf(" %6.2f |", GetChannelTriggerFlatTop(modID, ch));
printf(" %9.2f |", GetChannelTriggerThreshold(modID, ch));
printf(" %8s |", GetChannelPolarity(modID, ch) ? "Pos" : "Neg");
printf(" %8.2f |", GetChannelEnergyRiseTime(modID, ch));
printf(" %8.2f |", GetChannelEnergyFlatTop(modID, ch));
printf(" %5.2f |", GetChannelEnergyTau(modID, ch));
@ -469,12 +565,12 @@ void Pixie16::PrintChannelsMainSettings(unsigned short modID){
printf(" %7s |", "Off");
}
printf(" %4.2f |", GetChannelVOffset(modID, ch));
printf(" %4.2f \n", GetChannelBaseLinePrecent(modID, ch));
printf(" %4.2f %% \n", GetChannelBaseLinePrecent(modID, ch));
}
}
void Pixie16::WriteChannelSetting(std::string parName, double val, unsigned short modID, unsigned short ch, bool verbose ){
void Pixie16::SetChannelSetting(std::string parName, double val, unsigned short modID, unsigned short ch, bool verbose ){
retval = Pixie16WriteSglChanPar( const_cast<char*> (parName.c_str()), val, modID, ch);
if( CheckError("Pixie16WriteSglChanPar::"+parName) < 0 ) return;
@ -489,7 +585,7 @@ void Pixie16::SwitchCSRA(int bitwise, unsigned short modID, unsigned short ch){
if( CheckError("Pixie16ReadSglChanPar::CHANNEL_CSRA") < 0 ) return;
ParData = ((int)ParData) ^ bitwise;
WriteChannelSetting("CHANNEL_CSRA", ParData, modID, ch);
SetChannelSetting("CHANNEL_CSRA", ParData, modID, ch);
}
@ -523,7 +619,7 @@ void Pixie16::SetCSRABit(int bitwise, unsigned short val, unsigned short modID,
if( bitwise == CSRA_BIT::MO_VETO ) haha = val << 20;
if( bitwise == CSRA_BIT::EXT_TIMESTAMP ) haha = val << 21;
WriteChannelSetting("CHANNEL_CSRA", (temp | haha), modID, ch);
SetChannelSetting("CHANNEL_CSRA", (temp | haha), modID, ch);
}
@ -540,14 +636,20 @@ void Pixie16::PrintStatistics(unsigned short modID){
GetStatitics(modID);
if( retval >= 0 ){
printf(" Real (or RUN) Time : %9.3f sec \n", Pixie16ComputeRealTime (Statistics, modID));
printf(" ch | live time (sec) | input count rate | output count rate \n");
printf("-----+-----------------+------------------+-------------------\n");
double realTime = Pixie16ComputeRealTime (Statistics, modID);
printf(" Real (or RUN) Time : %9.3f sec \n", realTime);
printf(" ch | live time (sec) | input count rate | output count rate | trigger | events \n");
printf("-----+-----------------+------------------+-------------------+---------+--------\n");
for( int ch = 0; ch < 16; ch ++){
printf(" %2d |", ch);
printf(" %15.4f |", Pixie16ComputeLiveTime(Statistics, modID, ch));
printf(" %16.4f |", Pixie16ComputeInputCountRate(Statistics, modID, ch));
printf(" %17.4f \n", Pixie16ComputeOutputCountRate(Statistics, modID, ch));
double liveTime = Pixie16ComputeLiveTime(Statistics, modID, ch);
double ICR = Pixie16ComputeInputCountRate(Statistics, modID, ch);
double OCR = Pixie16ComputeOutputCountRate(Statistics, modID, ch);
printf(" %15.4f |", liveTime);
printf(" %16.4f |", ICR);
printf(" %17.4f |", OCR);
printf(" %7d |", (int) (ICR * liveTime) );
printf(" %7d \n", (int) (OCR * realTime) );
}
}
}
@ -592,14 +694,26 @@ void Pixie16::SaveSettings(std::string fileName){
}
}
/*
void Pixie16::SaveData(char * fileName, unsigned short isEndOfRun){
retval = Pixie16SaveExternalFIFODataToFile(fileName, &nFIFOWords, 0, isEndOfRun);
if( CheckError("Pixie16SaveExternalFIFODataToFile") < 0 ) return;
void Pixie16::OpenFile(std::string fileName, bool append){
}*/
if( !outFile.is_open() ) {
if( append ) {
outFile.open(fileName, std::ios::out | std::ios::binary | std::ios::app);
}else{
outFile.open(fileName, std::ios::out | std::ios::binary);
}
}
}
void Pixie16::SaveData(){
if( outFile.is_open() ) outFile.write(reinterpret_cast<char*>(ExtFIFO_Data), nFIFOWords * sizeof(uint32_t));
}
void Pixie16::CloseFile(){
outFile.close();
}
#endif

View File

@ -2,7 +2,8 @@
#define PIXIE16_H
#include <string>
#include <fstream>
#include "pixie16/pixie16.h"
#include "DataBlock.h"
enum CSRA_BIT{
@ -29,6 +30,18 @@ enum CSRA_BIT{
EXT_TIMESTAMP = 0x00200000,
};
enum MOD_CSRB_BIT{
WIRED_OR_TRIGGER_TO_PULLUP_RESIST = 0x00000001,
DIRECT_MODULUE = 0x00000010,
CHASSIS_MASTER = 0x00000040,
GLOBAL_FAST_TRIGGER = 0x00000080,
EXTERNAL_TRIGGER = 0x00000100,
USE_INHIBIT = 0x00000400,
DISTRIBUTE_CLOCK = 0x00000800,
SORT_TIMESTAMP = 0x00001000,
FAST_TRIGGER_TO_BACKPLANE = 0x00002000,
};
class Pixie16 {
private:
@ -56,6 +69,9 @@ private:
unsigned int * Statistics;
DataBlock * data;
unsigned int nextWord;
std::ofstream outFile;
/***
struct channelSetting{
@ -90,11 +106,20 @@ public:
void GetDigitizerInfo(unsigned short modID);
void BootDigitizers();
void AdjustOffset();
///========================= Setting
void GetDigitizerSettings(unsigned short modID);
unsigned int GetDigitizerSetting(std::string parName, unsigned short modID, bool verbose = false);
void PrintDigitizerSettings(unsigned short modID);
void SetDigitizerSetting(std::string parName, unsigned int val, unsigned short modID, bool verbose = false);
void SetDigitizerSynchWait(unsigned int val, unsigned short modID) { SetDigitizerSetting("SYNCH_WAIT", val, modID, 1);}
void SetDigitizerInSynch(unsigned int val, unsigned short modID) { SetDigitizerSetting("IN_SYNCH", val, modID, 1);}
void SetDigitizerPresetRunTime(double val_in_sec, unsigned short modID) { SetDigitizerSetting("HOST_RT_PRESET", Decimal2IEEEFloating(val_in_sec), modID, 1);}
double GetChannelSetting(std::string parName, unsigned short modID, unsigned short ch, bool verbose = false);
double GetChannelTriggerRiseTime (unsigned modID, unsigned short ch){ return GetChannelSetting("TRIGGER_RISETIME", modID, ch); }
@ -116,23 +141,24 @@ public:
bool GetChannelPolarity(unsigned short modID, unsigned short ch, bool verbose = false) {return GetCSRA(CSRA_BIT::POLARITY, modID, ch, verbose);}
bool GetChannelTraceOnOff(unsigned short modID, unsigned short ch, bool verbose = false) {return GetCSRA(CSRA_BIT::ENABLE_TRACE, modID, ch, verbose);}
void WriteChannelSetting(std::string parName, double val, unsigned short modID, unsigned short ch, bool verbose = false);
void WriteChannelTriggerRiseTime (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("TRIGGER_RISETIME", val, modID, ch, 1);}
void WriteChannelTriggerFlatTop (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("TRIGGER_FLATTOP", val, modID, ch, 1);}
void WriteChannelTriggerThreshold(double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("TRIGGER_THRESHOLD", val, modID, ch, 1);}
void WriteChannelEnergyRiseTime (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("ENERGY_RISETIME", val, modID, ch, 1);}
void WriteChannelEnergyFlatTop (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("ENERGY_FLATTOP", val, modID, ch, 1);}
void WriteChannelEnergyTau (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("TAU", val, modID, ch, 1);}
void WriteChannelTraceLenght (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("TRACE_LENGTH", val, modID, ch, 1);}
void WriteChannelTraceDelay (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("TRACE_DELAY", val, modID, ch, 1);}
void WriteChannelBaseLinePrecent (double val, unsigned short modID, unsigned short ch){ WriteChannelSetting("BASELINE_PERCENT", val, modID, ch, 1);}
void SetChannelSetting(std::string parName, double val, unsigned short modID, unsigned short ch, bool verbose = false);
void SetChannelTriggerRiseTime (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TRIGGER_RISETIME", val, modID, ch, 1);}
void SetChannelTriggerFlatTop (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TRIGGER_FLATTOP", val, modID, ch, 1);}
void SetChannelTriggerThreshold(double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TRIGGER_THRESHOLD", val, modID, ch, 1);}
void SetChannelEnergyRiseTime (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("ENERGY_RISETIME", val, modID, ch, 1);}
void SetChannelEnergyFlatTop (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("ENERGY_FLATTOP", val, modID, ch, 1);}
void SetChannelEnergyTau (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TAU", val, modID, ch, 1);}
void SetChannelTraceLenght (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TRACE_LENGTH", val, modID, ch, 1);}
void SetChannelTraceDelay (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TRACE_DELAY", val, modID, ch, 1);}
void SetChannelBaseLinePrecent (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("BASELINE_PERCENT", val, modID, ch, 1);}
void SetChannelVOffset (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("VOFFSET", val, modID, ch, 1);}
void SwitchCSRA(int bitwise, unsigned short modID, unsigned short ch);
void SetCSRABit(int bitwise, unsigned short val, unsigned short modID, unsigned short ch);
void SetChannleOnOff(bool enable, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::ENABLE_CHANNEL, enable, modID, ch); }
void SetPositivePolarity(bool positive, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::POLARITY, positive, modID, ch); }
void SetTraceOnOff(bool enable, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::ENABLE_TRACE, enable, modID, ch); }
void SetChannelOnOff(bool enable, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::ENABLE_CHANNEL, enable, modID, ch); }
void SetChannelPositivePolarity(bool positive, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::POLARITY, positive, modID, ch); }
void SetChannelTraceOnOff(bool enable, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::ENABLE_TRACE, enable, modID, ch); }
void SaveSettings(std::string fileName);
@ -152,7 +178,18 @@ public:
void GetBaseLines(unsigned short modID, unsigned short ch);
void ReadData(unsigned short modID);
void PrintData();
void PrintExtFIFOData(int a) { printf("%5d-%5d | %08X %08X %08X %08X \n", a, a+3, ExtFIFO_Data[a], ExtFIFO_Data[a+1], ExtFIFO_Data[a+2], ExtFIFO_Data[a+3]);}
unsigned int GetnFIFOWords() {return nFIFOWords;}
unsigned int GetNextWord() {return nextWord;}
DataBlock * GetData() {return data;}
void ProcessSingleData();
void ProcessData(int verbose = 0);
void OpenFile(std::string fileName, bool append);
void SaveData();
void CloseFile();
//void SaveData(char * fileName, unsigned short isEndOfRun);

View File

@ -14,8 +14,7 @@
#include "TString.h"
#include "TBenchmark.h"
#include "../mapping.h"
#include "../armory/DataBlock.h"
#include "DataBlock.h"
#define MAX_CRATES 2
#define MAX_BOARDS_PER_CRATE 13
@ -165,8 +164,8 @@ int evtReader::ReadBlock(int opt = 0){
data->trace_length = (header[3] >> 16) & 0x7FFF;
data->trace_out_of_range = header[3] >> 31;
data->id = data->crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (data->slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + data->ch;
data->detID = mapping[data->id];
//data->id = data->crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (data->slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + data->ch;
//data->detID = mapping[data->id];
data->ClearQDC();

View File

@ -271,6 +271,24 @@ bool execute_list_mode_run(const configuration& cfg, const double& runtime_in_se
std::cout << LOG("INFO") << "Starting list mode data run for " << runtime_in_seconds << " s."
<< std::endl;
std::cout << LOG("INFO") << "Calling Pixie16WriteSglModPar to read SYNCH_WAIT in Module 0."
<< std::endl;
unsigned int parData;
if (!verify_api_return_value(Pixie16ReadSglModPar("SYNCH_WAIT", &parData, 0),
"Pixie16ReadSglModPar - SYNC_WAIT"))
return false;
std::cout << LOG("INFO") << "SYNCH_WAIT in Module 0. = " << parData
<< std::endl;
std::cout << LOG("INFO") << "Calling Pixie16ReadSglModPar to read IN_SYNCH in Module 0."
<< std::endl;
if (!verify_api_return_value(Pixie16ReadSglModPar("IN_SYNCH", &parData, 0),
"Pixie16ReadSglModPar - IN_SYNC"))
return false;
std::cout << LOG("INFO") << "IN_SYNCH in Module 0. = " << parData
<< std::endl;
std::cout << LOG("INFO") << "Calling Pixie16WriteSglModPar to write SYNCH_WAIT = 1 in Module 0."
<< std::endl;
if (!verify_api_return_value(Pixie16WriteSglModPar("SYNCH_WAIT", 1, 0),
@ -302,7 +320,8 @@ bool execute_list_mode_run(const configuration& cfg, const double& runtime_in_se
while (std::chrono::duration_cast<std::chrono::duration<double>>(
std::chrono::steady_clock::now() - run_start_time)
.count() < runtime_in_seconds) {
for (unsigned short mod_num = 0; mod_num < cfg.num_modules(); mod_num++) {
// for (unsigned short mod_num = 0; mod_num < cfg.num_modules(); mod_num++) {
for (unsigned short mod_num = 0; mod_num < 1; mod_num++) {
if (Pixie16CheckRunStatus(mod_num) == 1) {
if (!verify_api_return_value(
Pixie16CheckExternalFIFOStatus(&num_fifo_words, mod_num),
@ -411,15 +430,15 @@ bool execute_mca_run(const unsigned int& mod, const double& runtime_in_seconds)
"Pixie16WriteSglModPar - HOST_RT_PRESET"))
return false;
std::cout << LOG("INFO") << "Calling Pixie16WriteSglModPar to write SYNCH_WAIT = 0 in Module 0."
std::cout << LOG("INFO") << "Calling Pixie16WriteSglModPar to write SYNCH_WAIT = 1 in Module 0."
<< std::endl;
if (!verify_api_return_value(Pixie16WriteSglModPar("SYNCH_WAIT", 0, mod),
if (!verify_api_return_value(Pixie16WriteSglModPar("SYNCH_WAIT", 1, mod),
"Pixie16WriteSglModPar - SYNC_WAIT"))
return false;
std::cout << LOG("INFO") << "Calling Pixie16WriteSglModPar to write IN_SYNCH = 1 in Module 0."
std::cout << LOG("INFO") << "Calling Pixie16WriteSglModPar to write IN_SYNCH = 0 in Module 0."
<< std::endl;
if (!verify_api_return_value(Pixie16WriteSglModPar("IN_SYNCH", 1, mod),
if (!verify_api_return_value(Pixie16WriteSglModPar("IN_SYNCH", 0, mod),
"Pixie16WriteSglModPar - IN_SYNC"))
return false;

5
example.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/bash
rm -f Pixie16Msg.log
./example $1 --config=example_config.json

121
test.cpp
View File

@ -14,6 +14,27 @@
#include "Pixie16Class.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TString.h"
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TGraph.h"
#include "TCutG.h"
#include "TMultiGraph.h"
#include "TApplication.h"
#include "TObjArray.h"
#include "TLegend.h"
#include "TRandom.h"
#include "TLine.h"
#include "TMacro.h"
#include "TRootCanvas.h"
long get_time();
static struct termios g_old_kbd_mode;
static void cooked(void); ///set keyboard behaviour as wait-for-enter
@ -36,8 +57,6 @@ void PrintCommands(){
printf("r ) RiseTime \n");
printf("t ) Trigger \n");
}
///##################################################
@ -50,12 +69,22 @@ int main(int argc, char *argv[]){
return 0;
}
pixie->GetDigitizerSettings(0);
TApplication * app = new TApplication("app", &argc, argv);
TCanvas * canvas = new TCanvas("canvas", "Canvas", 1800, 400);
canvas->Divide(3,1);
TH1F * hch = new TH1F("hch", "channel", 16, 0, 16);
TH1F * hE = new TH1F("hE", "energy", 400, 0, 30000);
TGraph * gTrace = new TGraph();
gTrace->GetXaxis()->SetTitle("time [ch, 1 ch = 4 ns]");
//pixie->SetDigitizerPresetRunTime(100000, 0);
//pixie->SetDigitizerSynchWait(0, 0); // not simultaneously
//pixie->SetDigitizerInSynch(1, 0); //not simultaneously
pixie->PrintDigitizerSettings(0);
///pixie->GetHostCSR(0);
///pixie->SaveSettings("haha.set");
/*
pixie->GetPolarity(0, 6, 1);
pixie->SetPolarity(false, 0, 6);
@ -64,42 +93,78 @@ int main(int argc, char *argv[]){
pixie->GetPolarity(0, 6, 1);
*/
int ch = 6;
double time = 0.5; ///sec
/*
for( int i = 0; i < 16; i++){
if( i == ch ){
pixie->WriteChannelTriggerThreshold(10, 0, i);
pixie->WriteChannelEnergyRiseTime(4, 0, i);
pixie->WriteChannelEnergyTau(50, 0, i);
pixie->WriteChannelTraceLenght(1, 0, i);
pixie->WriteChannelTraceDelay(0.5, 0, i);
pixie->SetPositivePolarity(true, 0, i);
pixie->SetTraceOnOff(false, 0, i);
}else{
pixie->WriteChannelTriggerThreshold(500, 0, i);
pixie->SetChannleOnOff(false, 0, i);
}
pixie->SetChannelTriggerThreshold(5000, 0, i);
pixie->SetChannelOnOff(false, 0, i);
pixie->SetChannelTraceOnOff(false, 0, i);
pixie->SetChannelVOffset(0, 0, i);
}
*/
pixie->WriteChannelTriggerThreshold(500, 0, 6);
* */
//pixie->SetChannelEnergyRiseTime(2, 0, ch);
pixie->SetChannelTriggerThreshold(300, 0, ch);
//pixie->SetChannelEnergyTau(50, 0, ch);
//pixie->SetChannelOnOff(true, 0, ch);
//pixie->SetChannelPositivePolarity(true, 0, ch);
//pixie->SetChannelTraceOnOff(true, 0, ch);
pixie->SetChannelVOffset(-1.0, 0, ch);
pixie->SetChannelTraceLenght(10, 0, ch);
pixie->SetChannelTraceDelay(2, 0, ch);
pixie->SaveSettings("test_ryan.set");
pixie->PrintChannelAllSettings(0, ch);
pixie->PrintChannelsMainSettings(0);
printf("start run for %f sec\n", time);
//pixie->AdjustOffset();
uint32_t StartTime = get_time(), CurrentTime = get_time();
pixie->StartRun(1);
///pixie->GetHostCSR(0);
DataBlock * data = pixie->GetData();
while( CurrentTime - StartTime < time * 1000 ){
pixie->ReadData(0);
while( pixie->GetNextWord() < pixie->GetnFIFOWords() ){
//for( int i = pixie->GetNextWord(); i < pixie->GetNextWord() + 314 ; i++) pixie->PrintExtFIFOData(i);
pixie->ProcessSingleData();
//data->Print(0);
//printf("--------------next word : %d (%d) | event lenght : %d \n", pixie->GetNextWord(), pixie->GetnFIFOWords(), data->eventLength);
hch->Fill( data->ch);
hE->Fill( data->energy );
if( data->trace_length > 0 ) {
for( int i = 0 ; i < data->trace_length; i++){
gTrace->SetPoint(i, i, data->trace[i]);
//if( i % 200 == 0 ) printf("%i, %d \n", i, data->trace[i]);
}
canvas->cd(3); gTrace->Draw("APL");
}
canvas->cd(1); hch->Draw();
canvas->cd(2); hE->Draw();
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
}
CurrentTime = get_time();
}
usleep(time*1e6);
pixie->StopRun();
pixie->ReadData(0);
//pixie->PrintData();
@ -198,6 +263,8 @@ int main(int argc, char *argv[]){
//delete pixie;
app->Run();
printf("================ end of program. \n");
return 0;
}

View File

@ -9,7 +9,7 @@
31,
31,
1,
36,
291,
32,
1,
1,
@ -93,22 +93,22 @@
120
],
"ChanCSRa": [
18848,
16800,
16800,
16800,
16800,
16800,
16548,
16800,
16800,
16800,
16800,
16800,
16800,
16800,
16800,
16800
18592,
16544,
16544,
16544,
16544,
16544,
16804,
16544,
16544,
16544,
16544,
16544,
16544,
16544,
16544,
16544
],
"ChanCSRb": [
0,
@ -255,22 +255,22 @@
10
],
"FastThresh": [
2000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000,
10000
65535,
65535,
65535,
65535,
65535,
65535,
6000,
65535,
65535,
65535,
65535,
65535,
65535,
65535,
65535,
65535
],
"FastTrigBackLen": [
10,
@ -417,22 +417,22 @@
2
],
"OffsetDAC": [
38048,
38304,
37664,
38048,
38240,
38304,
37984,
37856,
38816,
38112,
38688,
38368,
38496,
38624,
38240,
38048
32768,
32768,
32768,
32768,
32768,
32768,
10922,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
],
"PAFlength": [
1768,
@ -441,7 +441,7 @@
1768,
1768,
1768,
710,
642,
1768,
1768,
1768,
@ -495,7 +495,7 @@
95,
95,
95,
80,
48,
95,
95,
95,
@ -513,7 +513,7 @@
97,
97,
97,
82,
50,
97,
97,
97,
@ -729,7 +729,7 @@
78,
78,
78,
63,
31,
78,
78,
78,
@ -765,7 +765,7 @@
5000,
5000,
5000,
250,
2500,
5000,
5000,
5000,
@ -801,7 +801,7 @@
768,
768,
768,
648,
392,
768,
768,
768,
@ -1054,7 +1054,7 @@
"SynchWait": 1,
"TrigConfig": [
6212,
0,
64,
0,
0
],