-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.cpp
130 lines (95 loc) · 3.23 KB
/
reader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
compilation command:
g++ -std=c++11 reader.cpp -o reader
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdint>
#include <vector>
using namespace std;
struct RECORD
{
uint64_t hits;
uint64_t time;
};
double unitVolt(int unitArb)
{
double result;
result = (double)(unitArb*10)/4095;
return result;
}
int main()
{
string prefix = "scan-hv";
string name;
int i, n, size,hv,th, event, layer, strip;
struct RECORD buffer;
ofstream outfile;
outfile.open("plot.txt");
// open file
int numberOfEvent;
vector <int>collection(64);
vector <int> ns(4);
for(hv=2400; hv<=3400;hv+=50){
for(th=90;th<=140;th+=5){
name = prefix + to_string(hv) + "-th" + to_string(th)+".dat";
cout << "file " << name << endl;
ifstream infile(name, ios::binary | ios::in);
if(!infile.is_open())
{
cerr << "cannot open file " << name << endl;
continue;
}
// get file size
infile.seekg (0, ios::end);
size = infile.tellg();
infile.seekg (0, ios::beg);
cout << "file size " << size << endl;
// calculate number of events because one event is 16 char
n = size / 16;
int ne=0;
int numberOfStrip;
numberOfEvent=0;
// read all events
for(event = 0; event < n; event += 1)
{
// read event
infile.read((char *) &buffer, 16);
// print event
ios::fmtflags flags(cout.flags());
cout << setfill(' ') << setw(8) << dec << event << " "; //rempli avec des espaces afin d'avoir 8caractères au total
cout << setfill('0') << setw(16) << hex << buffer.time << " "; //rempli avec des 0 afin d'avoir 16 caractères au total.
cout << setfill('0') << setw(16) << hex << buffer.hits << " ";
cout.flags(flags);//sets some format flags for cout that affect the insertion operation
ns[0]=0;
ns[1]=0;
ns[2]=0;
ns[3]=0;
numberOfStrip=0;
// print layers and strips with hits
for(i = 0; i < 64; i += 1)
{
if((buffer.hits >> i & 1) == 0) continue;
layer = i / 16;
strip = i % 16;
cout << layer << ":" << strip << " ";
ns[layer]+=1;
numberOfStrip+=1;
//if(strip>0 && strip<15) numberOfStrip+=1;
}
//collection[numberOfStrip]+=1;
//outfile << numberOfStrip << endl;
/*if (numberOfStrip<=12 && numberOfStrip>=4){
numberOfEvent+=1;
}*/
if (ns[0]<3 && ns[1]<3 && ns[2]<3 && ns[3]<3) ++ne;
}
outfile <<unitVolt(hv) << " "<<th<<" "<<ne<<endl;
}
}
//for(i=0;i<64;i+=1){
// outfile << i << " "<< collection[i] << endl;}
outfile.close();
return 0;
}