-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitx.C
More file actions
41 lines (36 loc) · 1.18 KB
/
itx.C
File metadata and controls
41 lines (36 loc) · 1.18 KB
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
// convert Igor text file to ROOT format
void itx(char* input, char* output)
{
// create output file to hold histograms
TFile *fo = new TFile(output,"recreate");
// define histogram for each channel
const int ncha = 4; // PIXIE-4
TH1I *h[ncha]= {0};
const int nbit = (int) pow(2,15); // 15-bit
for (int i=0; i<ncha; i++)
h[i] = new TH1I(Form("h%d",i),
Form("Channel %d;ADC counts;Entries;",i),nbit,0,nbit);
ifstream fi(input); // open input file
// read input file line by line
const int nc=256; // read 256 characters in each line
char line[nc];
int icha=0; // should be in [0, ncha)
int ibin=1; // should be in [1, nbit]
bool isData=false; // flag
while(fi.getline(line, nc)) { // get a line
if (line[0]=='E') isData=false;// meet lines starting with 'END'
if (isData) {
h[icha]->SetBinContent(ibin, atoi(line));
ibin++;
if (ibin>nbit) { // finish one channel
icha++;
ibin=1;
}
}
if (line[0]=='B') isData=true; // meet lines starting with 'BEGIN'
}
fi.close(); // close input file
// save histograms to ouptut file
fo->Write();
fo->Close();
}