2024-01-12 19:12:37 -05:00
|
|
|
#ifndef Hit_H
|
|
|
|
#define Hit_H
|
|
|
|
|
2024-02-19 11:53:29 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2024-01-12 19:12:37 -05:00
|
|
|
class Hit{
|
|
|
|
public:
|
2024-01-19 03:07:16 -05:00
|
|
|
unsigned short sn;
|
2024-07-17 14:53:49 -04:00
|
|
|
unsigned short ch;
|
2024-01-12 19:12:37 -05:00
|
|
|
unsigned short energy;
|
|
|
|
unsigned short energy2;
|
|
|
|
unsigned long long timestamp;
|
|
|
|
unsigned short fineTime;
|
2024-01-25 18:34:58 -05:00
|
|
|
bool pileUp;
|
2024-01-12 19:12:37 -05:00
|
|
|
|
2024-01-19 03:07:16 -05:00
|
|
|
unsigned short traceLength;
|
2024-01-12 19:12:37 -05:00
|
|
|
std::vector<short> trace;
|
|
|
|
|
|
|
|
Hit(){
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear(){
|
|
|
|
sn = 0;
|
|
|
|
ch = 0;
|
|
|
|
energy = 0;
|
|
|
|
energy2 = 0;
|
|
|
|
timestamp = 0;
|
|
|
|
fineTime = 0;
|
2024-01-19 03:07:16 -05:00
|
|
|
traceLength = 0;
|
2024-01-25 18:34:58 -05:00
|
|
|
pileUp = false;
|
2024-01-12 19:12:37 -05:00
|
|
|
trace.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Print(){
|
2024-01-25 18:34:58 -05:00
|
|
|
printf("(%5d, %2d) %6d %16llu, %6d, %d, %5ld\n", sn, ch, energy, timestamp, fineTime, pileUp, trace.size());
|
2024-01-16 15:39:41 -05:00
|
|
|
}
|
|
|
|
|
2024-01-19 03:07:16 -05:00
|
|
|
void PrintTrace(){
|
|
|
|
for( unsigned short i = 0; i < traceLength; i++){
|
|
|
|
printf("%3u | %6d \n", i, trace[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-04 12:22:23 -05:00
|
|
|
// Define operator< for sorting
|
2024-01-16 15:39:41 -05:00
|
|
|
bool operator<(const Hit& other) const {
|
|
|
|
return timestamp < other.timestamp;
|
2024-07-17 14:53:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-17 15:30:27 -04:00
|
|
|
void WriteHitsToCAENBinary(FILE * file, uint32_t header){
|
2024-07-17 14:53:49 -04:00
|
|
|
if( file == nullptr ) return;
|
|
|
|
|
|
|
|
uint32_t flag = 0;
|
|
|
|
uint8_t waveFormCode = 1; // input
|
|
|
|
|
2024-07-17 15:30:27 -04:00
|
|
|
// uint16_t header = 0xCAE1; // default to have the energy only
|
|
|
|
// if( energy2 > 0 ) header += 0x4;
|
|
|
|
// if( traceLength > 0 && withTrace ) header += 0x8;
|
2024-07-17 14:53:49 -04:00
|
|
|
|
2024-07-17 15:30:27 -04:00
|
|
|
size_t dummy;
|
2024-07-17 14:53:49 -04:00
|
|
|
dummy = fwrite(&sn, 2, 1, file);
|
|
|
|
dummy = fwrite(&ch, 2, 1, file);
|
|
|
|
|
|
|
|
uint64_t timestampPS = timestamp * 1000 + fineTime;
|
|
|
|
dummy = fwrite(×tampPS, 8, 1, file);
|
|
|
|
|
|
|
|
dummy = fwrite(&energy, 2, 1, file);
|
|
|
|
|
2024-07-17 15:30:27 -04:00
|
|
|
if( (header & 0x4) ) dummy = fwrite(&energy2, 2, 1, file);
|
2024-07-17 14:53:49 -04:00
|
|
|
|
|
|
|
dummy = fwrite(&flag, 4, 1, file);
|
|
|
|
|
2024-07-17 15:30:27 -04:00
|
|
|
if( traceLength > 0 && (header & 0x8) ){
|
2024-07-17 14:53:49 -04:00
|
|
|
dummy = fwrite(&waveFormCode, 1, 1, file);
|
|
|
|
dummy = fwrite(&traceLength, 4, 1, file);
|
|
|
|
for( int j = 0; j < traceLength; j++ ){
|
|
|
|
dummy = fwrite(&(trace[j]), 2, 1, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( dummy != 1 ) printf("write file error.\n");
|
|
|
|
|
2024-01-12 19:12:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|