9 using namespace RdNoiseConverter;
18 const int noiseFilter = 10;
20 for (
auto const& bin: noiseEvent.
traceCh0) {
21 if (
abs(bin) - meanCh0 > noiseFilter)
25 for (
auto const& bin: noiseEvent.
traceCh1) {
26 if (
abs(bin) - meanCh1 > noiseFilter)
29 const bool noisy = (
std::max(counterCh0, counterCh1) > 30 ?
true :
false);
40 FILE* inpfile = fopen(fileName.c_str(),
"r");
42 TFile* outfile =
new TFile(
"myNoise.root",
"RECREATE",
"File for all noise traces");
48 int status = fread(&seconds,
sizeof(
int), 1, inpfile);
52 std::cout <<
"File corrupt, no traces to write!" << std::endl;
57 std::cout <<
"End of file reached, noise file written." << std::endl;
62 fseek(inpfile,
sizeof(
int)*51, SEEK_CUR);
72 for (
int i=0; i<2048; i++) {
73 fseek(inpfile,
sizeof(
int), SEEK_CUR);
75 fread(&ADCRaw[0],
sizeof(
int), 6, inpfile);
77 ns = (ADCRaw[5] >> 1) & 0xfff;
78 ew = (ADCRaw[5] >> 17) & 0xfff;
80 noiseEvent.
traceCh0[i] = ( ns > 2047 ) ? ns - 4096: ns;
81 noiseEvent.
traceCh1[i] = ( ew > 2047 ) ? ew - 4096: ew;
87 const double meanch0 = sumch0 / 2048;
88 const double meanch1 = sumch1 / 2048;
90 if (bin2root.
IsNoiseTrace(noiseEvent, meanch0, meanch1)) {
94 const int currGPSUnixOffset = 18;
95 noiseEvent.
evtno = counter;
96 noiseEvent.
sec = seconds + currGPSUnixOffset;
101 std::string treeName =
"Noisetree_" + std::to_string(counter);
102 TTree* tree =
new TTree(treeName.c_str(),
"The tree of noise");
103 tree->Branch(
"traceCh0", &noiseEvent.
traceCh0,
"traceCh0[2048]/I");
104 tree->Branch(
"traceCh1", &noiseEvent.
traceCh1,
"traceCh1[2048]/I");
105 tree->Branch(
"stationId", &noiseEvent.
stationId,
"stationId/I");
106 tree->Branch(
"sec", &noiseEvent.
sec,
"sec/I");
107 tree->Branch(
"nanosec", &noiseEvent.
nanosec,
"nanosec/I");
108 tree->Branch(
"evtno", &noiseEvent.
evtno,
"evtno/I");
111 tree->ResetBranchAddresses();
114 if (counter == maxTraces)
121 std::cout <<
"Given maximum number of traces reached, noise file written." << std::endl;
127 int main(
int argc,
char* argv[])
131 const std::string fileName = argv[1];
132 const int maxTraces = std::atoi(argv[2]);
bool IsNoiseTrace(const EventN &noiseEvent, const double meanCh0, const double meanCh1)
int main(int argc, char *argv[])
double abs(const SVector< n, T > &v)
void ReadFromBinaryFile(const std::string fileName, const int maxTraces)