2022-01-06 13:18:29 -05:00
|
|
|
/**********************************************************/
|
|
|
|
/* */
|
|
|
|
/* Modified by Ryan From */
|
|
|
|
/* */
|
|
|
|
/* PXI SCAN CODE -- J.M. Allmond (ORNL) -- July 2016 */
|
|
|
|
/* */
|
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "TFile.h"
|
|
|
|
#include "TTree.h"
|
|
|
|
#include "TMath.h"
|
|
|
|
#include "TBenchmark.h"
|
|
|
|
|
|
|
|
#define RAND ((float) rand() / ((unsigned int) RAND_MAX + 1)) // random number in interval (0,1)
|
|
|
|
|
|
|
|
#define MAX_CRATES 2
|
|
|
|
#define MAX_BOARDS_PER_CRATE 13
|
|
|
|
#define MAX_CHANNELS_PER_BOARD 16
|
|
|
|
#define BOARD_START 2
|
|
|
|
|
|
|
|
#define MAX_ID MAX_CRATES*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD
|
|
|
|
|
|
|
|
#define HEADER_LENGTH 4 //unit = words with 4 bytes per word
|
|
|
|
#define MAX_SUB_LENGTH 2016 //unit = words with 4 bytes per word ; 2004 --> 40 micro-second trace + 4 word header
|
|
|
|
|
|
|
|
#define RAWE_REBIN_FACTOR 2.0 // Rebin 32k pixie16 spectra to something smaller to fit better into 8k.
|
|
|
|
|
|
|
|
#include "../mapping.h"
|
|
|
|
|
2022-01-18 14:23:47 -05:00
|
|
|
#include "../armory/evtReader.h"
|
2022-01-06 13:18:29 -05:00
|
|
|
|
|
|
|
unsigned long long int dataCount=0;
|
|
|
|
unsigned long long int pileUpCount=0;
|
|
|
|
unsigned long long int evtCount=0;
|
|
|
|
|
|
|
|
///////////////////////////////////
|
|
|
|
// START OF MAIN FUNCTION //
|
|
|
|
///////////////////////////////////
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
printf("=====================================\n");
|
|
|
|
printf("=== evt.to --> root ===\n");
|
|
|
|
printf("=====================================\n");
|
|
|
|
|
|
|
|
// Check that the corrent number of arguments were provided.
|
2022-01-22 16:41:53 -05:00
|
|
|
if (argc <= 3) {
|
2022-01-06 13:18:29 -05:00
|
|
|
printf("Incorrect number of arguments:\n");
|
2022-01-22 16:41:53 -05:00
|
|
|
printf("%s [outFile] [timeWindow] [to File1] [to File2] .... \n", argv[0]);
|
|
|
|
printf(" outFile : output root file name\n");
|
2022-01-06 13:18:29 -05:00
|
|
|
printf(" timeWindow : number of tick, 1 tick = 10 ns. default = 100 \n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
TString outFileName = argv[1];
|
|
|
|
int timeWindow = atoi(argv[2]);
|
|
|
|
int nFile = argc - 3;
|
|
|
|
TString inFileName[nFile];
|
|
|
|
for( int i = 0 ; i < nFile ; i++){
|
|
|
|
inFileName[i] = argv[i+3];
|
|
|
|
}
|
2022-01-06 13:18:29 -05:00
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
printf("====================================\n");
|
2022-01-06 13:18:29 -05:00
|
|
|
|
2022-01-18 14:23:47 -05:00
|
|
|
evtReader * evt = new evtReader();
|
|
|
|
DataBlock * data = evt->data;
|
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
printf(" Number of input file : %d \n", nFile);
|
|
|
|
printf(" out file : \033[1;31m%s\033[m\n", outFileName.Data());
|
|
|
|
printf(" Event building time window : %d tics = %d nsec \n", timeWindow, timeWindow*10);
|
2022-01-06 13:18:29 -05:00
|
|
|
|
2022-01-18 14:23:47 -05:00
|
|
|
|
2022-01-06 13:18:29 -05:00
|
|
|
TFile * outRootFile = new TFile(outFileName, "recreate");
|
|
|
|
outRootFile->cd();
|
2022-03-22 20:55:23 -04:00
|
|
|
TTree * tree = new TTree("tree", outFileName);
|
2022-01-06 13:18:29 -05:00
|
|
|
|
2022-01-07 13:10:17 -05:00
|
|
|
unsigned long long evID = 0;
|
|
|
|
int multi = 0;
|
2022-01-07 14:46:32 -05:00
|
|
|
int id[MAX_ID] = {0};
|
|
|
|
double e[MAX_ID] = {TMath::QuietNaN()};
|
|
|
|
unsigned long long e_t[MAX_ID] = {0};
|
2022-03-10 13:59:06 -05:00
|
|
|
bool pileup[MAX_ID] = {0};
|
2022-01-13 18:23:41 -05:00
|
|
|
int qdc[MAX_ID][8] = {0};
|
2022-01-22 16:41:53 -05:00
|
|
|
int multiCry = 0 ; /// this is total multiplicity for all crystal
|
|
|
|
int runID = 0; // date-run-fileID, Dec15-02-001 = 1502001
|
|
|
|
int multiGagg = 0;
|
2022-01-07 13:10:17 -05:00
|
|
|
//unsigned short pileup[MAXMULTI];
|
2022-01-06 13:18:29 -05:00
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
tree->Branch("evID", &evID, "event_ID/l");
|
|
|
|
tree->Branch("multi", &multi, "multi/I");
|
|
|
|
tree->Branch("detID", id, "detID[multi]/I");
|
|
|
|
tree->Branch("e", e, "e[multi]/D");
|
|
|
|
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
|
2022-03-10 13:59:06 -05:00
|
|
|
tree->Branch("pileup", pileup, "pileup[multi]/O");
|
2022-01-22 16:41:53 -05:00
|
|
|
tree->Branch("qdc", qdc, "qdc[multi][8]/I");
|
|
|
|
tree->Branch("multiCry", &multiCry, "multiplicity_crystal/I");
|
|
|
|
tree->Branch("multiGagg", &multiGagg, "multiplicity_GAGG/I");
|
|
|
|
tree->Branch("runID", &runID, "runID/I");
|
|
|
|
|
|
|
|
int countGP = 0; //gamma-particle coincident
|
2022-02-02 16:37:27 -05:00
|
|
|
double totalDataSize = 0;
|
2022-02-10 13:45:05 -05:00
|
|
|
int outFileCount = 0;
|
2022-01-22 16:41:53 -05:00
|
|
|
|
|
|
|
for( int i = 0; i < nFile; i++){
|
2022-01-21 15:57:40 -05:00
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
evt->OpenFile(inFileName[i]);
|
|
|
|
if( evt->IsOpen() == false ) continue;
|
|
|
|
|
2022-02-10 13:45:05 -05:00
|
|
|
printf("==================================================== %d / %d\n", i+1, nFile);
|
2022-01-22 16:41:53 -05:00
|
|
|
printf("\033[1;31m%s \033[m\n", inFileName[i].Data());
|
2022-01-21 15:57:40 -05:00
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
int pos = inFileName[i].Last('/');
|
|
|
|
TString temp = inFileName[i];
|
|
|
|
temp.Remove(0, pos+1);
|
|
|
|
temp.Remove(0, 3);
|
|
|
|
temp.Remove(2, 1);
|
|
|
|
temp.Remove(4, 1);
|
|
|
|
temp.Remove(7);
|
|
|
|
runID = atoi(temp.Data());
|
|
|
|
|
|
|
|
long long int etime = -1;
|
|
|
|
long long int tdif = -1;
|
2022-01-18 14:23:47 -05:00
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
|
|
|
|
while ( evt->IsEndOfFile() == false ) { //main while loop
|
|
|
|
|
2022-01-18 14:23:47 -05:00
|
|
|
if ( evt->ReadBlock() == -1) break;
|
2022-01-13 18:23:41 -05:00
|
|
|
|
2022-01-06 13:18:29 -05:00
|
|
|
//Set reference time for event building
|
|
|
|
if (etime == -1) {
|
2022-01-18 14:23:47 -05:00
|
|
|
etime = data->time;
|
2022-01-07 14:46:32 -05:00
|
|
|
tdif = 0;
|
2022-01-07 13:10:17 -05:00
|
|
|
multi = 0;
|
2022-03-10 13:59:06 -05:00
|
|
|
multiCry = 0;
|
|
|
|
multiGagg = 0;
|
2022-01-07 13:10:17 -05:00
|
|
|
}else {
|
2022-01-18 14:23:47 -05:00
|
|
|
tdif = data->time - etime;
|
2022-01-06 13:18:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check for end of event, rewind, and break out of while loop
|
|
|
|
if (tdif > timeWindow) {
|
2022-01-18 14:23:47 -05:00
|
|
|
|
2022-02-02 16:37:27 -05:00
|
|
|
//Gate
|
2022-02-10 13:45:05 -05:00
|
|
|
//if( multiCry > 2 && multiGagg ==0 ) {
|
|
|
|
//
|
|
|
|
outRootFile->cd();
|
|
|
|
tree->Fill();
|
|
|
|
//
|
|
|
|
// countGP++;
|
|
|
|
//}
|
2022-01-22 16:41:53 -05:00
|
|
|
|
|
|
|
evID ++;
|
|
|
|
|
2022-01-18 14:23:47 -05:00
|
|
|
etime = data->time;
|
|
|
|
tdif = 0;
|
|
|
|
multi = 0;
|
|
|
|
multiCry = 0;
|
2022-01-22 16:41:53 -05:00
|
|
|
multiGagg = 0;
|
|
|
|
|
2022-03-04 16:13:40 -05:00
|
|
|
int haha = data->crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (data->slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + data->ch;
|
|
|
|
id[multi] = mapping[haha];
|
2022-01-18 14:23:47 -05:00
|
|
|
e[multi] = data->energy;
|
|
|
|
e_t[multi] = data->time;
|
2022-03-10 13:59:06 -05:00
|
|
|
pileup[multi] = data->pileup;
|
2022-01-18 14:23:47 -05:00
|
|
|
for( int i = 0; i < 8; i++) qdc[multi][i] = data->QDCsum[i];
|
|
|
|
multi++ ;
|
2022-03-04 16:13:40 -05:00
|
|
|
if( id[multi] < 100 ) multiCry ++;
|
|
|
|
if( id[multi] >= 200 ) multiGagg ++;
|
2022-01-22 16:41:53 -05:00
|
|
|
|
2022-01-06 13:18:29 -05:00
|
|
|
}else{
|
|
|
|
//if within time window, fill array;
|
2022-03-04 16:13:40 -05:00
|
|
|
int haha = data->crate*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (data->slot-BOARD_START)*MAX_CHANNELS_PER_BOARD + data->ch;
|
2022-03-10 13:59:06 -05:00
|
|
|
id[multi] = mapping[haha];
|
|
|
|
e[multi] = data->energy;
|
|
|
|
e_t[multi] = data->time;
|
|
|
|
pileup[multi] = data->pileup;
|
|
|
|
for( int i = 0; i < 8; i++) qdc[multi][i] = data->QDCsum[i];
|
2022-01-07 13:10:17 -05:00
|
|
|
multi++ ;
|
2022-03-04 16:13:40 -05:00
|
|
|
if( id[multi] < 100 ) multiCry ++;
|
|
|
|
if( id[multi] >= 200 ) multiGagg ++;
|
2022-01-22 16:41:53 -05:00
|
|
|
|
2022-01-06 13:18:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// total pileups
|
2022-01-18 14:23:47 -05:00
|
|
|
if (data->pileup == 1) {
|
2022-01-06 13:18:29 -05:00
|
|
|
pileUpCount++;
|
|
|
|
}
|
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
evt->PrintStatus(10000);
|
2022-01-18 14:23:47 -05:00
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
} // end main while loop
|
|
|
|
|
|
|
|
evt->PrintStatus(1);
|
|
|
|
printf("\n\n\n");
|
|
|
|
printf(" total number of event built : %llu\n", evID);
|
2022-03-10 13:59:06 -05:00
|
|
|
//printf(" total number of Gamma - GAGG coincdient : %d (%.3f %%)\n", countGP, countGP*1.0/evID);
|
2022-01-22 16:41:53 -05:00
|
|
|
|
|
|
|
outRootFile->cd();
|
|
|
|
tree->Write();
|
2022-03-10 13:59:06 -05:00
|
|
|
|
|
|
|
totalDataSize += (evt->GetFileSize())/1024./1024./1024.;
|
2022-02-02 16:37:27 -05:00
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
double rootFileSize = outRootFile->GetSize()/1024./1024./1024. ; // in GB
|
|
|
|
printf(" ----------- root file size : %.3f GB\n", rootFileSize);
|
2022-02-02 16:37:27 -05:00
|
|
|
printf(" ---------- total read size : %.3f GB\n", totalDataSize);
|
|
|
|
printf(" ----------- reduction rate : %.3f %%\n", rootFileSize*100./totalDataSize);
|
2022-03-10 13:59:06 -05:00
|
|
|
|
|
|
|
evt->CloseFile();
|
2022-02-10 13:45:05 -05:00
|
|
|
|
2022-03-10 13:59:06 -05:00
|
|
|
/*
|
2022-02-10 13:45:05 -05:00
|
|
|
if( rootFileSize > 3.0 ) {
|
|
|
|
break;
|
2022-03-10 13:59:06 -05:00
|
|
|
}*/
|
2022-02-10 13:45:05 -05:00
|
|
|
|
|
|
|
///try to open a new root file when file size > 2 GB
|
|
|
|
/*if( rootFileSize > 2.0 ) {
|
|
|
|
|
|
|
|
outRootFile->Close();
|
|
|
|
delete outRootFile;
|
|
|
|
delete tree;
|
|
|
|
outFileCount += 1;
|
|
|
|
|
|
|
|
if( outFileCount > 5 ) break;
|
|
|
|
|
|
|
|
TString outFileName2 = outFileName;
|
|
|
|
outFileName2.Insert(outFileName.Sizeof() - 6, Form("_%03d",outFileCount));
|
|
|
|
outRootFile = new TFile( outFileName2, "recreate");
|
|
|
|
|
|
|
|
tree = new TTree("tree", "tree");
|
|
|
|
tree->Branch("evID", &evID, "event_ID/l");
|
|
|
|
tree->Branch("multi", &multi, "multi/I");
|
|
|
|
tree->Branch("detID", id, "detID[multi]/I");
|
|
|
|
tree->Branch("e", e, "e[multi]/D");
|
|
|
|
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
|
|
|
|
tree->Branch("qdc", qdc, "qdc[multi][8]/I");
|
|
|
|
tree->Branch("multiCry", &multiCry, "multiplicity_crystal/I");
|
|
|
|
tree->Branch("multiGagg", &multiGagg, "multiplicity_GAGG/I");
|
|
|
|
tree->Branch("runID", &runID, "runID/I");
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2022-01-22 16:41:53 -05:00
|
|
|
}
|
|
|
|
|
2022-01-06 13:18:29 -05:00
|
|
|
|
|
|
|
outRootFile->Close();
|
|
|
|
|
2022-01-18 14:23:47 -05:00
|
|
|
printf("\n\n\n==================== finished.\r\n");
|
2022-01-21 15:57:40 -05:00
|
|
|
|
2022-03-10 13:59:06 -05:00
|
|
|
//printf(" number of Gamma - GAGG coincdient : %d\n", countGP);
|
2022-01-07 13:10:17 -05:00
|
|
|
|
2022-01-06 13:18:29 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|