EventBuilder: fundation of multiple files, enable trace stored as TGraph
This commit is contained in:
parent
12f17fe912
commit
04f98d1923
18
ClassData.h
18
ClassData.h
|
@ -19,9 +19,10 @@ class Data{
|
|||
|
||||
public:
|
||||
|
||||
int DPPType;
|
||||
int DPPType; /// this is set from the boardID from the Board Agg. header when it is > 0
|
||||
unsigned short boardSN;
|
||||
float ch2ns;
|
||||
|
||||
unsigned int nByte; /// number of byte
|
||||
char *buffer; /// readout buffer
|
||||
uint32_t AllocatedSize;
|
||||
|
@ -96,6 +97,8 @@ inline Data::Data(){
|
|||
|
||||
ch2ns = 2.0;
|
||||
boardSN = 0;
|
||||
DPPType = V1730_DPP_PHA_CODE;
|
||||
|
||||
buffer = NULL;
|
||||
for ( int i = 0; i < MaxNChannels; i++) TotNumEvents[i] = 0;
|
||||
ClearData();
|
||||
|
@ -157,7 +160,7 @@ inline void Data::ClearData(){
|
|||
inline void Data::SaveBuffer(const char * fileName){
|
||||
|
||||
char saveFileName[100];
|
||||
sprintf(saveFileName, "%s_%03u.fsu", fileName , saveFileIndex);
|
||||
sprintf(saveFileName, "%s_%03d_%03d_%03u.fsu", fileName , boardSN, DPPType, saveFileIndex);
|
||||
|
||||
FILE * haha = fopen(saveFileName, "a+");
|
||||
fseek(haha, 0L, SEEK_END);
|
||||
|
@ -238,7 +241,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
ClearTriggerRate();
|
||||
|
||||
do{
|
||||
if( verbose >= 1 ) printf("######################################### Board Agg.\n");
|
||||
if( verbose >= 1 ) printf("Data::DecodeBuffer ######################################### Board Agg.\n");
|
||||
unsigned int word = ReadBuffer(nw, verbose);
|
||||
if( ( (word >> 28) & 0xF ) == 0xA ) { /// start of Board Agg
|
||||
unsigned int nWord = word & 0x0FFFFFFF ;
|
||||
|
@ -248,7 +251,14 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
unsigned int BoardID = ((word >> 27) & 0x1F);
|
||||
bool BoardFailFlag = ((word >> 26) & 0x1 );
|
||||
unsigned int ChannelMask = ( word & 0xFF ) ;
|
||||
if( verbose >= 1 ) printf("Board ID : %d, FailFlag = %d, ChannelMask = 0x%X\n", BoardID, BoardFailFlag, ChannelMask);
|
||||
if( verbose >= 1 ) printf("Board ID(type) : %d, FailFlag = %d, ChannelMask = 0x%X\n", BoardID, BoardFailFlag, ChannelMask);
|
||||
|
||||
if( BoardID > 0 ) {
|
||||
switch(BoardID){
|
||||
case 0x8 : DPPType = V1730_DPP_PSD_CODE; break;
|
||||
case 0xB : DPPType = V1730_DPP_PHA_CODE; break;
|
||||
}
|
||||
}
|
||||
|
||||
nw = nw + 2;
|
||||
unsigned int AggCounter = ReadBuffer(nw, verbose);
|
||||
|
|
|
@ -90,6 +90,7 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose
|
|||
LinkType = CAEN_DGTZ_OpticalLink ;
|
||||
ret = (int) CAEN_DGTZ_OpenDigitizer(LinkType, portID, boardID, VMEBaseAddress, &handle);
|
||||
}
|
||||
ErrorMsg("=== Open Digitizer");
|
||||
|
||||
if (ret != 0) {
|
||||
if( verbose) printf("Can't open digitizer\n");
|
||||
|
@ -106,18 +107,20 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose
|
|||
switch(BoardInfo.Model){
|
||||
case CAEN_DGTZ_V1730: ch2ns = 2.0; break; ///ns -> 500 MSamples/s
|
||||
case CAEN_DGTZ_V1725: ch2ns = 4.0; break; ///ns -> 250 MSamples/s
|
||||
default : ch2ns = 4.0; break;
|
||||
}
|
||||
data->ch2ns = ch2ns;
|
||||
data->boardSN = BoardInfo.SerialNumber;
|
||||
ADCbits = BoardInfo.ADC_NBits;
|
||||
ADCFullSize = (unsigned int)( pow(2, ADCbits) -1 );
|
||||
//SetBoardID(BoardInfo.SerialNumber);
|
||||
}
|
||||
}
|
||||
|
||||
///====================== Check DPP firmware revision
|
||||
sscanf(BoardInfo.AMC_FirmwareRel, "%d", &DPPType);
|
||||
data->DPPType = DPPType;
|
||||
/// change address 0xEF08 (5 bits), this will reflected in the 2nd word of the Board Agg. header.
|
||||
ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardID, (DPPType & 0xF));
|
||||
if ( verbose ){
|
||||
PrintBoard();
|
||||
if (DPPType < 0x80 ) {
|
||||
|
@ -127,11 +130,13 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose
|
|||
printf("\e[32m\t %s \e[0m", GetDPPString().c_str());
|
||||
}
|
||||
}
|
||||
ErrorMsg("========== Set BoardID");
|
||||
|
||||
///======================= Check virtual probe
|
||||
int probes[MAX_SUPPORTED_PROBES];
|
||||
int numProbes;
|
||||
ret = CAEN_DGTZ_GetDPP_SupportedVirtualProbes(handle, 1, probes, &numProbes);
|
||||
ErrorMsg("=== Get Supported Virtual Probes");
|
||||
if( verbose ){
|
||||
printf("\t==== supported virtual probe (number of Probe : %d)\n", numProbes);
|
||||
for( int i = 0 ; i < numProbes; i++){
|
||||
|
|
447
EventBuilder.cpp
447
EventBuilder.cpp
|
@ -2,25 +2,14 @@
|
|||
|
||||
#include "TROOT.h"
|
||||
#include "TSystem.h"
|
||||
#include "TApplication.h"
|
||||
#include "TCanvas.h"
|
||||
#include "TClonesArray.h"
|
||||
#include "TGraph.h"
|
||||
#include "TH1.h"
|
||||
#include "TFile.h"
|
||||
#include "TTree.h"
|
||||
|
||||
#define MAX_MULTI 100
|
||||
#define NTimeWinForBuffer 3
|
||||
|
||||
unsigned long get_time(){
|
||||
unsigned long time_us;
|
||||
struct timeval t1;
|
||||
struct timezone tz;
|
||||
gettimeofday(&t1, &tz);
|
||||
time_us = (t1.tv_sec) * 1000000 + t1.tv_usec;
|
||||
return time_us;
|
||||
}
|
||||
|
||||
TFile * outRootFile = NULL;
|
||||
TTree * tree = NULL;
|
||||
|
||||
|
@ -31,13 +20,228 @@ unsigned short ch[MAX_MULTI] = {0}; /// chID
|
|||
unsigned short e[MAX_MULTI] = {0}; /// 15 bit
|
||||
unsigned long long e_t[MAX_MULTI] = {0}; /// timestamp 47 bit
|
||||
unsigned short e_f[MAX_MULTI] = {0}; /// fine time 10 bit
|
||||
//TODO std::vector<unsigned short> wave[MAX_ID]; /// waveform
|
||||
|
||||
void EventBuilder(Data * data, const unsigned int timeWin, bool isLastData = false){
|
||||
|
||||
class Trace{
|
||||
public:
|
||||
Trace() {trace.clear(); }
|
||||
~Trace();
|
||||
void Clear() { trace.clear(); };
|
||||
Trace operator = (std::vector<unsigned short> v){
|
||||
Trace tt;
|
||||
for( int i = 0 ; i < (int) v.size() ; i++){
|
||||
trace.push_back(v[i]);
|
||||
}
|
||||
return tt;
|
||||
}
|
||||
std::vector<unsigned short> trace;
|
||||
};
|
||||
|
||||
/// using TClonesArray to hold the trace in TGraph
|
||||
TClonesArray * arrayTrace = NULL;
|
||||
unsigned short traceLength[MAX_MULTI] = {0};
|
||||
TGraph * trace = NULL;
|
||||
|
||||
template<typename T> void swap(T * a, T *b );
|
||||
int partition(int arr[], int kaka[], TString file[], int start, int end);
|
||||
void quickSort(int arr[], int kaka[], TString file[], int start, int end);
|
||||
unsigned long get_time();
|
||||
void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn = false, bool isLastData = false, unsigned int verbose = 0);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
printf("=====================================\n");
|
||||
printf("=== *.fsu Events Builder ===\n");
|
||||
printf("=====================================\n");
|
||||
if (argc <= 3) {
|
||||
printf("Incorrect number of arguments:\n");
|
||||
printf("%s [timeWindow] [traceOn/Off] [verbose] [inFile1] [inFile2] .... \n", argv[0]);
|
||||
printf(" timeWindow : number of tick, 1 tick. default = 100 \n");
|
||||
printf(" traceOn/Off : is traces stored \n");
|
||||
printf(" verbose : > 0 for debug \n");
|
||||
printf(" Output file name is contructed from inFile1 \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// File format must be YYY...Y_runXXX_AAA_BBB_CCC.fsu
|
||||
/// YYY...Y = prefix
|
||||
/// XXX = runID, 3 digits
|
||||
/// AAA = board Serial Number, 3 digits
|
||||
/// BBB = DPPtype, 3 digits
|
||||
/// CCC = over size index, 3 digits
|
||||
|
||||
///============= read input
|
||||
unsigned int timeWindow = atoi(argv[1]);
|
||||
bool traceOn = atoi(argv[2]);
|
||||
unsigned int debug = atoi(argv[3]);
|
||||
int nFile = argc - 4;
|
||||
TString inFileName[nFile];
|
||||
for( int i = 0 ; i < nFile ; i++){
|
||||
inFileName[i] = argv[i+4];
|
||||
}
|
||||
|
||||
/// Form outFileName;
|
||||
TString outFileName = inFileName[0];
|
||||
int pos = outFileName.Index("_");
|
||||
pos = outFileName.Index("_", pos+1);
|
||||
outFileName.Remove(pos);
|
||||
outFileName += ".root";
|
||||
printf("-------> Out file name : %s \n", outFileName.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 = %u \n", timeWindow);
|
||||
printf("=====================================\n");
|
||||
|
||||
///============= sorting file by the serial number & order
|
||||
int ID[nFile]; /// serial+ order*1000;
|
||||
int type[nFile];
|
||||
for( int i = 0; i < nFile; i++){
|
||||
int snPos = inFileName[i].Index("_");
|
||||
snPos = inFileName[i].Index("_", snPos+1);
|
||||
int sn = atoi(&inFileName[i][snPos+1]);
|
||||
type[i] = atoi(&inFileName[i][snPos+5]);
|
||||
int order = atoi(&inFileName[i][snPos+9]);
|
||||
ID[i] = sn + order * 1000;
|
||||
}
|
||||
quickSort(&(ID[0]), &(type[0]), &(inFileName[0]), 0, nFile-1);
|
||||
for( int i = 0 ; i < nFile; i++){
|
||||
printf("%d | %6d | %3d | %s \n", i, ID[i], type[i], inFileName[i].Data());
|
||||
}
|
||||
|
||||
///=============== Seperate files
|
||||
std::vector<int> idCat;
|
||||
std::vector<std::vector<int>> typeCat;
|
||||
std::vector<std::vector<TString>> fileCat;
|
||||
for( int i = 0; i < nFile; i++){
|
||||
if( ID[i] / 1000 == 0 ) {
|
||||
std::vector<TString> temp = {inFileName[i]};
|
||||
std::vector<int> temp2 = {type[i]};
|
||||
fileCat.push_back(temp);
|
||||
typeCat.push_back(temp2);
|
||||
idCat.push_back(ID[i]%1000);
|
||||
}else{
|
||||
for( int p = 0; p < (int) idCat.size(); p++){
|
||||
if( (ID[i] % 1000) == idCat[p] ) {
|
||||
fileCat[p].push_back(inFileName[i]);
|
||||
typeCat[p].push_back(type[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("=====================================\n");
|
||||
for( int i = 0; i < (int) idCat.size(); i++){
|
||||
printf("............ %d \n", idCat[i]);
|
||||
for( int j = 0; j< (int) fileCat[i].size(); j++){
|
||||
printf("%s | %d\n", fileCat[i][j].Data(), typeCat[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
///============= Open input Files
|
||||
printf("##############################################\n");
|
||||
FILE * haha = fopen(fileCat[0][0], "r");
|
||||
if( haha == NULL ){
|
||||
printf("#### Cannot open file : %s. Abort.\n", fileCat[0][0].Data());
|
||||
return -1;
|
||||
}
|
||||
fseek(haha, 0L, SEEK_END);
|
||||
const size_t inFileSize = ftell(haha);
|
||||
printf("%s | file size : %d Byte = %.2f MB\n", fileCat[0][0].Data(), (int) inFileSize, inFileSize/1024./1024.);
|
||||
fclose(haha);
|
||||
|
||||
|
||||
Data * data = new Data();
|
||||
data->DPPType = typeCat[0][0];
|
||||
data->boardSN = idCat[0];
|
||||
data->SetSaveWaveToMemory(true);
|
||||
|
||||
///============= Set Root Tree
|
||||
outRootFile = new TFile(outFileName, "recreate");
|
||||
tree = new TTree("tree", outFileName);
|
||||
tree->Branch("evID", &evID, "event_ID/l");
|
||||
tree->Branch("multi", &multi, "multi/s");
|
||||
tree->Branch("bd", bd, "bd[multi]/s");
|
||||
tree->Branch("ch", ch, "ch[multi]/s");
|
||||
tree->Branch("e", e, "e[multi]/s");
|
||||
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
|
||||
tree->Branch("e_f", e_f, "e_timestamp[multi]/s");
|
||||
|
||||
if( traceOn ) {
|
||||
arrayTrace = new TClonesArray("TGraph");
|
||||
tree->Branch("traceLength", traceLength, "traceLength[multi]/s");
|
||||
tree->Branch("trace", arrayTrace, 2560000);
|
||||
arrayTrace->BypassStreamer();
|
||||
}
|
||||
|
||||
|
||||
///============= Main Loop
|
||||
haha = fopen(inFileName[0], "r");
|
||||
int countBdAgg = 0;
|
||||
|
||||
unsigned long currentTime = 0;
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
do{
|
||||
|
||||
///========== Get 1 aggreration
|
||||
oldTime = get_time();
|
||||
if( debug) printf("*********************** file pos : %d, %lu\n", (int) ftell(haha), oldTime);
|
||||
unsigned int word[1]; /// 4 bytes
|
||||
size_t dump = fread(word, 4, 1, haha);
|
||||
fseek(haha, -4, SEEK_CUR);
|
||||
|
||||
short header = ((word[0] >> 28 ) & 0xF);
|
||||
if( header != 0xA ) break;
|
||||
|
||||
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
||||
|
||||
if( debug) printf("Board Agg. has %d word = %d bytes\n", aggSize/4, aggSize);
|
||||
countBdAgg ++;
|
||||
|
||||
char * buffer = new char[aggSize];
|
||||
dump = fread(buffer, aggSize, 1, haha);
|
||||
|
||||
data->DecodeBuffer(buffer, aggSize, false, 0);
|
||||
|
||||
delete buffer;
|
||||
|
||||
currentTime = get_time();
|
||||
|
||||
if( debug) {
|
||||
printf("~~~~~~~~~~~~~~~~ time used : %lu \n", currentTime - oldTime);
|
||||
data->PrintStat();
|
||||
}
|
||||
|
||||
EventBuilder(data, timeWindow, traceOn, false, debug);
|
||||
|
||||
if( debug) printf("---------- event built : %llu \n", evID);
|
||||
|
||||
if( debug > 0 && evID > debug ) break;
|
||||
|
||||
}while(!feof(haha) && ftell(haha) <= inFileSize);
|
||||
|
||||
fclose(haha);
|
||||
|
||||
///printf("==================== end of loop \n");
|
||||
EventBuilder(data, timeWindow, traceOn, true, debug);
|
||||
|
||||
tree->Write();
|
||||
outRootFile->Close();
|
||||
|
||||
printf("========================= finsihed.\n");
|
||||
printf("total events built = %llu \n", evID);
|
||||
printf("=======> saved to %s \n", outFileName.Data());
|
||||
|
||||
}
|
||||
|
||||
void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool isLastData, unsigned int verbose){
|
||||
|
||||
///printf("============= build Event\n");
|
||||
|
||||
///data->PrintData();
|
||||
if( verbose) data->PrintData();
|
||||
|
||||
/// find the last event timestamp;
|
||||
unsigned long long firstTimeStamp = -1;
|
||||
|
@ -47,19 +251,18 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool isLastData = fal
|
|||
if( data->Timestamp[chI][0] > 0 && data->Timestamp[chI][0] < firstTimeStamp ) {
|
||||
firstTimeStamp = data->Timestamp[chI][0];
|
||||
}
|
||||
|
||||
unsigned short ev = data->NumEvents[chI]-1;
|
||||
if( data->Timestamp[chI][ev] > 0 && data->Timestamp[chI][ev] > lastTimeStamp ) {
|
||||
lastTimeStamp = data->Timestamp[chI][ev];
|
||||
}
|
||||
|
||||
if( data->Timestamp[chI][ev] > 0 && data->Timestamp[chI][ev] < smallestLastTimeStamp ){
|
||||
smallestLastTimeStamp = data->Timestamp[chI][ev];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///printf("================ time range : %llu - %llu, smallest Last %llu\n", firstTimeStamp, lastTimeStamp, smallestLastTimeStamp );
|
||||
if( firstTimeStamp == -1 ) return;
|
||||
|
||||
if( verbose) printf("================ time range : %llu - %llu, smallest Last %llu\n", firstTimeStamp, lastTimeStamp, smallestLastTimeStamp );
|
||||
unsigned short lastEv[MaxNChannels] = {0}; /// store the last event number for each ch
|
||||
unsigned short exhaustedCh = 0;
|
||||
|
||||
|
@ -86,16 +289,34 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool isLastData = fal
|
|||
}
|
||||
}
|
||||
|
||||
if( traceOn ) arrayTrace->Clear("C");
|
||||
|
||||
if( breakFlag ) break;
|
||||
if( !isLastData && ((smallestLastTimeStamp - time1st) < NTimeWinForBuffer * timeWin) ) break;
|
||||
if( ch1st > MaxNChannels ) break;
|
||||
|
||||
multi ++;
|
||||
|
||||
bd[multi-1] = data->boardSN;
|
||||
ch[multi-1] = ch1st;
|
||||
e[multi-1] = data->Energy[ch1st][lastEv[ch1st]];
|
||||
e_t[multi-1] = data->Timestamp[ch1st][lastEv[ch1st]];
|
||||
e_f[multi-1] = data->fineTime[ch1st][lastEv[ch1st]];
|
||||
if( traceOn ){
|
||||
traceLength[multi-1] = (unsigned short) data->Waveform1[ch1st][lastEv[ch1st]].size();
|
||||
|
||||
if( verbose )printf("------- trace Length : %u \n", traceLength[multi-1]);
|
||||
|
||||
trace = (TGraph *) arrayTrace->ConstructedAt(multi-1, "C");
|
||||
trace->Clear();
|
||||
for( int hh = 0; hh < traceLength[multi-1]; hh++){
|
||||
trace->SetPoint(hh, hh, data->Waveform1[ch1st][lastEv[ch1st]][hh]);
|
||||
|
||||
if( verbose )if( hh % 200 == 0 ) printf("%3d | %u \n", hh, data->Waveform1[ch1st][lastEv[ch1st]][hh]);
|
||||
}
|
||||
|
||||
|
||||
///if( verbose) trace->Print();
|
||||
}
|
||||
lastEv[ch1st] ++;
|
||||
|
||||
/// build event
|
||||
|
@ -111,6 +332,15 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool isLastData = fal
|
|||
e[multi-1] = data->Energy[chX][ev];
|
||||
e_t[multi-1] = data->Timestamp[chX][ev];
|
||||
e_f[multi-1] = data->fineTime[chX][ev];
|
||||
if( traceOn ){
|
||||
traceLength[multi-1] = (unsigned short) data->Waveform1[chX][ev].size();
|
||||
|
||||
trace = (TGraph *) arrayTrace->ConstructedAt(multi-1, "C");
|
||||
trace->Clear();
|
||||
for( int hh = 0; hh < traceLength[multi-1]; hh++){
|
||||
trace->SetPoint(hh, hh, data->Waveform1[chX][ev][hh]);
|
||||
}
|
||||
}
|
||||
lastEv[chX] = ev + 1;
|
||||
|
||||
if( lastEv[chX] == data->NumEvents[chX] ) exhaustedCh ++;
|
||||
|
@ -118,16 +348,18 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool isLastData = fal
|
|||
}
|
||||
}
|
||||
|
||||
///printf("=============== multi : %d , ev : %llu\n", multi, evID);
|
||||
///for( int ev = 0; ev < multi; ev++){
|
||||
/// printf("%3d, ch : %2d, %u, %llu \n", ev, ch[ev], e[ev], e_t[ev]);
|
||||
///}
|
||||
///
|
||||
///printf("=============== Last Ev , exhaustedCh %d \n", exhaustedCh);
|
||||
///for( int chI = 0; chI < MaxNChannels ; chI++){
|
||||
/// if( lastEv[chI] == 0 ) continue;
|
||||
/// printf("%2d, %d \n", chI, lastEv[chI]);
|
||||
///}
|
||||
if( verbose) {
|
||||
printf("=============== multi : %d , ev : %llu\n", multi, evID);
|
||||
for( int ev = 0; ev < multi; ev++){
|
||||
printf("%3d, ch : %2d, %u, %llu \n", ev, ch[ev], e[ev], e_t[ev]);
|
||||
}
|
||||
|
||||
printf("=============== Last Ev , exhaustedCh %d \n", exhaustedCh);
|
||||
for( int chI = 0; chI < MaxNChannels ; chI++){
|
||||
if( lastEv[chI] == 0 ) continue;
|
||||
printf("%2d, %d \n", chI, lastEv[chI]);
|
||||
}
|
||||
}
|
||||
|
||||
///========== Quick Sort the timestamp ??or left it to analyzer, monitor?
|
||||
|
||||
|
@ -139,6 +371,8 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool isLastData = fal
|
|||
/// clear
|
||||
multi = 0;
|
||||
|
||||
if( verbose > 0 && evID > verbose ) break;
|
||||
|
||||
}while( exhaustedCh < MaxNChannels - 1 );
|
||||
|
||||
///========== clear built data
|
||||
|
@ -155,102 +389,61 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool isLastData = fal
|
|||
data->NumEvents[chI] = data->NumEvents[chI] - lastEv[chI];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
printf("=====================================\n");
|
||||
printf("=== *.fsu Events Builder ===\n");
|
||||
printf("=====================================\n");
|
||||
// Check that the corrent number of arguments were provided.
|
||||
if (argc <= 2) {
|
||||
printf("Incorrect number of arguments:\n");
|
||||
printf("%s [outFile] [timeWindow] [inFile1] [inFile2] .... \n", argv[0]);
|
||||
printf(" outFile : output root file name\n");
|
||||
printf(" timeWindow : number of tick, 1 tick. default = 100 \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
TString outFileName = argv[1];
|
||||
unsigned int timeWindow = atoi(argv[2]);
|
||||
int nFile = argc - 3;
|
||||
TString inFileName[nFile];
|
||||
for( int i = 0 ; i < nFile ; i++){
|
||||
inFileName[i] = argv[i+3];
|
||||
}
|
||||
|
||||
printf(" Time Window = %u \n", timeWindow);
|
||||
|
||||
/// Open input Files
|
||||
FILE * haha = fopen(inFileName[0], "r");
|
||||
fseek(haha, 0L, SEEK_END);
|
||||
const size_t inFileSize = ftell(haha);
|
||||
printf("file size : %d Byte = %.2f MB\n", (int) inFileSize, inFileSize/1024./1024.);
|
||||
fclose(haha);
|
||||
|
||||
Data * data = new Data();
|
||||
//TODO get the DPPType and boardSN from file
|
||||
data->DPPType = V1730_DPP_PHA_CODE;
|
||||
data->boardSN = 323;
|
||||
data->SetSaveWaveToMemory(true);
|
||||
|
||||
|
||||
///============= Set Root Tree
|
||||
outRootFile = new TFile(outFileName, "recreate");
|
||||
tree = new TTree("tree", outFileName);
|
||||
tree->Branch("evID", &evID, "event_ID/l");
|
||||
tree->Branch("multi", &multi, "multi/s");
|
||||
tree->Branch("bd", bd, "bd[multi]/s");
|
||||
tree->Branch("ch", ch, "ch[multi]/s");
|
||||
tree->Branch("e", e, "e[multi]/s");
|
||||
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
|
||||
tree->Branch("e_f", e_f, "e_timestamp[multi]/s");
|
||||
|
||||
///============= Main Loop
|
||||
haha = fopen(inFileName[0], "r");
|
||||
int countBdAgg = 0;
|
||||
|
||||
unsigned long currentTime = 0;
|
||||
unsigned long oldTime = 0;
|
||||
do{
|
||||
|
||||
///========== Get 1 aggreration
|
||||
oldTime = get_time();
|
||||
///printf("*********************** file pos : %d, %lu\n", (int) ftell(haha), oldTime);
|
||||
unsigned int word[1]; /// 4 bytes
|
||||
size_t dump = fread(word, 4, 1, haha);
|
||||
fseek(haha, -4, SEEK_CUR);
|
||||
|
||||
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
||||
short header = ((word[0] >> 28 ) & 0xF);
|
||||
if( header != 0xA ) break;
|
||||
///printf("Board Agg. has %d word = %d bytes\n", aggSize/4, aggSize);
|
||||
countBdAgg ++;
|
||||
|
||||
char * buffer = new char[aggSize];
|
||||
dump = fread(buffer, aggSize, 1, haha);
|
||||
|
||||
data->DecodeBuffer(buffer, aggSize, false, 0);
|
||||
|
||||
currentTime = get_time();
|
||||
|
||||
///printf("~~~~~~~~~~~~~~~~ time used : %lu \n", currentTime - oldTime);
|
||||
///data->PrintStat();
|
||||
|
||||
EventBuilder(data, timeWindow);
|
||||
|
||||
}while(!feof(haha) && ftell(haha) <= inFileSize);
|
||||
|
||||
fclose(haha);
|
||||
|
||||
///printf("==================== end of loop \n");
|
||||
|
||||
EventBuilder(data, timeWindow, true);
|
||||
|
||||
tree->Write();
|
||||
outRootFile->Close();
|
||||
|
||||
printf("========================= finsihed.\n");
|
||||
printf("total events built = %llu \n", evID);
|
||||
if( verbose > 0 ) data->PrintData();
|
||||
|
||||
}
|
||||
|
||||
unsigned long get_time(){
|
||||
unsigned long time_us;
|
||||
struct timeval t1;
|
||||
struct timezone tz;
|
||||
gettimeofday(&t1, &tz);
|
||||
time_us = (t1.tv_sec) * 1000000 + t1.tv_usec;
|
||||
return time_us;
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void swap(T * a, T *b ){
|
||||
T temp = * b;
|
||||
*b = *a;
|
||||
*a = temp;
|
||||
}
|
||||
|
||||
int partition(int arr[], int kaka[], TString file[], int start, int end){
|
||||
int pivot = arr[start];
|
||||
int count = 0;
|
||||
for (int i = start + 1; i <= end; i++) {
|
||||
if (arr[i] <= pivot) count++;
|
||||
}
|
||||
/// Giving pivot element its correct position
|
||||
int pivotIndex = start + count;
|
||||
swap(&arr[pivotIndex], &arr[start]);
|
||||
swap(&file[pivotIndex], &file[start]);
|
||||
swap(&kaka[pivotIndex], &kaka[start]);
|
||||
|
||||
/// Sorting left and right parts of the pivot element
|
||||
int i = start, j = end;
|
||||
while (i < pivotIndex && j > pivotIndex) {
|
||||
while (arr[i] <= pivot) {i++;}
|
||||
while (arr[j] > pivot) {j--;}
|
||||
if (i < pivotIndex && j > pivotIndex) {
|
||||
int ip = i++;
|
||||
int jm = j--;
|
||||
swap( &arr[ip], &arr[jm]);
|
||||
swap(&file[ip], &file[jm]);
|
||||
swap(&kaka[ip], &kaka[jm]);
|
||||
}
|
||||
}
|
||||
return pivotIndex;
|
||||
}
|
||||
|
||||
void quickSort(int arr[], int kaka[], TString file[], int start, int end){
|
||||
/// base case
|
||||
if (start >= end) return;
|
||||
/// partitioning the array
|
||||
int p = partition(arr, kaka, file, start, end);
|
||||
/// Sorting the left part
|
||||
quickSort(arr, kaka, file, start, p - 1);
|
||||
/// Sorting the right part
|
||||
quickSort(arr, kaka, file, p + 1, end);
|
||||
}
|
||||
|
|
|
@ -729,7 +729,8 @@ void * MainWindow::RunThread(void * ptr){
|
|||
uint32_t ElapsedTime = 0;
|
||||
|
||||
TString dataFileName = ProgramSetting::DataSavingPath + dataPrefix->GetText();
|
||||
dataFileName += Form("_run%03d_%03d", (int) runIDEntry->GetNumber(), (int) digi[boardID]->GetSerialNumber());
|
||||
//dataFileName += Form("_run%03d_%03d_%3s", (int) runIDEntry->GetNumber(), (int) digi[boardID]->GetSerialNumber(), digi[boardID]->GetDPPStringShort().c_str());
|
||||
dataFileName += Form("_run%03d", (int) runIDEntry->GetNumber());
|
||||
|
||||
printf("|%s|\n", dataFileName.Data());
|
||||
|
||||
|
|
170
readTrace.C
Normal file
170
readTrace.C
Normal file
|
@ -0,0 +1,170 @@
|
|||
#include <TROOT.h>
|
||||
#include <TChain.h>
|
||||
#include <TFile.h>
|
||||
#include <TSelector.h>
|
||||
#include <TCanvas.h>
|
||||
#include <TGraph.h>
|
||||
#include <TClonesArray.h>
|
||||
#include <TBenchmark.h>
|
||||
#include <TMath.h>
|
||||
#include <TF1.h>
|
||||
#include <TLine.h>
|
||||
#include <iostream>
|
||||
|
||||
void readTrace(TString fileName, int minDetID = 0, int maxDetID = 1000, bool isGoodOnly = false){
|
||||
|
||||
/**///==============================================================
|
||||
|
||||
TFile * f1 = new TFile (fileName, "read");
|
||||
TTree * tree = (TTree *) f1->Get("tree");
|
||||
|
||||
int totnumEntry = tree->GetEntries();
|
||||
printf( "========== total Entry : %d \n", totnumEntry);
|
||||
|
||||
TCanvas * cRead = new TCanvas("cRead", "Read Trace", 0, 1500, 800, 300);
|
||||
cRead->Divide(1,1);
|
||||
for( int i = 1; i <= 2 ; i++){
|
||||
cRead->cd(i)->SetGrid();
|
||||
}
|
||||
cRead->SetGrid();
|
||||
|
||||
gStyle->SetOptFit(0);
|
||||
|
||||
/**///==============================================================
|
||||
TClonesArray * arr = new TClonesArray("TGraph");
|
||||
//tree->GetBranch("trace")->SetAutoDelete(kFALSE);
|
||||
//tree->GetBranch("trace")->SetAutoDelete(kTRUE);
|
||||
tree->SetBranchAddress("trace", &arr);
|
||||
|
||||
//TODO UP-Down arrow for pervious-next control
|
||||
TLine timeVLine;
|
||||
|
||||
TLatex text ;
|
||||
text.SetNDC();
|
||||
text.SetTextFont(62);
|
||||
text.SetTextSize(0.06);
|
||||
text.SetTextColor(2);
|
||||
|
||||
bool breakFlag = false;
|
||||
bool lastEvFlag = false;
|
||||
vector<int> oldEv;
|
||||
int evPointer = 0;
|
||||
|
||||
for( int ev = 0; ev < totnumEntry; ev++){
|
||||
|
||||
if( lastEvFlag ) {
|
||||
ev = oldEv[evPointer];
|
||||
lastEvFlag = false;
|
||||
}
|
||||
tree->GetEntry(ev);
|
||||
|
||||
int nTrace = arr->GetEntriesFast();
|
||||
|
||||
int countJ = 0;
|
||||
|
||||
for( int j = 0; j < nTrace ; j++){
|
||||
|
||||
TGraph * g = (TGraph*) arr->At(j);
|
||||
|
||||
TString gTitle;
|
||||
gTitle = g->GetTitle();
|
||||
///printf("TGraph Title : %s\n", gTitle.Data());
|
||||
|
||||
int detID = 0;
|
||||
int pos = gTitle.Index("id=");
|
||||
gTitle.Remove(0, pos+3);
|
||||
gTitle.Remove(3);
|
||||
detID = gTitle.Atoi();
|
||||
|
||||
if( !(minDetID <= detID && detID <= maxDetID ) ) continue;
|
||||
|
||||
if( countJ == 0 ) printf("-------------------------------- ev : %d, evPointer : %d| num Trace : %d\n", ev, evPointer, nTrace);
|
||||
|
||||
|
||||
TF1 * gFit = (TF1 *) g->FindObject("gFit");
|
||||
|
||||
TString kTitle;
|
||||
|
||||
if( gFit != NULL ){
|
||||
double base, time = 0, riseTime, energy, chiSq;
|
||||
energy = gFit->GetParameter(0);
|
||||
time = gFit->GetParameter(1);
|
||||
riseTime = gFit->GetParameter(2);
|
||||
base = gFit->GetParameter(3);
|
||||
chiSq = gFit->GetChisquare()/gFit->GetNDF();
|
||||
int kind = gFit->GetLineColor();
|
||||
int det = gFit->GetLineStyle();
|
||||
|
||||
///if( !(minDetID <= det && det <= maxDetID ) ) continue;
|
||||
|
||||
if( isGoodOnly){
|
||||
if( abs(energy) < 1.5* g->GetRMS(2) ) continue;
|
||||
if( time > gFit->GetXmax() || time < gFit->GetXmin()) continue;
|
||||
if( time > 200 || time < 20) continue;
|
||||
if( riseTime > gFit->GetXmax()/7. || riseTime < 0 ) continue;
|
||||
}
|
||||
|
||||
//if( energy < 400 ) continue;
|
||||
|
||||
kTitle = Form("(%3d,%d), base: %8.1f, rise: %6.2f, time: %6.1f, energy: %8.1f | chi2: %8.1f, RMS: %6.1f",
|
||||
det, kind, base, riseTime, time, energy, chiSq, g->GetRMS(2));
|
||||
|
||||
printf("%s |(q = break, w = last one)", kTitle.Data());
|
||||
|
||||
|
||||
timeVLine.SetX1(time);
|
||||
timeVLine.SetX2(time);
|
||||
timeVLine.SetY1(-1000);
|
||||
timeVLine.SetY2(20000);
|
||||
timeVLine.SetLineColor(4);
|
||||
}
|
||||
|
||||
cRead->cd(1);
|
||||
//cRead->Clear();
|
||||
g->Draw("AC");
|
||||
//g->GetXaxis()->SetRangeUser(0, g->GetN());
|
||||
//g->GetYaxis()->SetRangeUser(7500, 35000);
|
||||
timeVLine.Draw("same");
|
||||
if( gFit != NULL ) text.DrawText(0.11, 0.85, kTitle.Data());
|
||||
|
||||
cRead->Update();
|
||||
gSystem->ProcessEvents();
|
||||
|
||||
|
||||
char s[80];
|
||||
fgets(s, sizeof s, stdin);
|
||||
|
||||
if( s[0] == 113 ) { // 'q' = 113
|
||||
breakFlag = true;
|
||||
break;
|
||||
}else if( s[0] == 119 ) { // 'w' = 119
|
||||
|
||||
if( j > 0 || countJ > 0 ) {
|
||||
j = j - 2;
|
||||
}
|
||||
|
||||
if( (j == 0 && (int)oldEv.size() >= 0 && evPointer > 0 ) || countJ == 0 ) {
|
||||
if( evPointer > 0 ) evPointer --;
|
||||
if( evPointer == 0 ) printf(" the first event!!! \n");
|
||||
lastEvFlag = true;
|
||||
//printf(" ev : %d, evPt : %d \n", oldEv[evPointer], evPointer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
countJ ++;
|
||||
|
||||
}
|
||||
if( breakFlag ) break;
|
||||
|
||||
if( lastEvFlag == false && countJ > 0 ){
|
||||
if( oldEv.size() == evPointer ) oldEv.push_back(ev);
|
||||
evPointer ++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//gROOT->ProcessLine(".q");
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user