-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathm2r.C
More file actions
83 lines (73 loc) · 2.16 KB
/
m2r.C
File metadata and controls
83 lines (73 loc) · 2.16 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
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
/*
this macro reads in the mca binary file
save the results to root histograms and then
save all histograms to file
*/
void convert_mca_to_histograms(Char_t* mca_filename, Char_t* output_histo_filename)
{
//
const int nchannels=4; // this must be user-defined
const int NMCAC=32768;
//
Char_t MCAValue_block[131072];
unsigned long int MCAValue[32768];
//
//--> prepare output histograms
//
TH1F* hmca[nchannels];
for (int i=0; i<nchannels; i++) {
hmca[i] = new TH1F(Form("hmca_%d",i),Form("hmca_%d",i),
NMCAC,0.0,float(NMCAC) );
}
//
//--> read in binary file
//
std::ifstream inputfile;
inputfile.open(mca_filename, ios::in | ios::binary | ios::ate);
short int a;
short int b;
short unsigned int returnint;
Int_t temp_int;
for (Int_t icha=0; icha<nchannels; icha++) {
//------> read in the block
inputfile.seekg(icha*131072);
inputfile.read(MCAValue_block,131072);
//------> process the block
for (Int_t i=0; i<32768; i++) {
Int_t j=i*4;
a=MCAValue_block[j];
b=MCAValue_block[j+1];
returnint=0;
for (Int_t ii=0; ii<8; ii++) {
if (a & (1<<ii) ) { returnint |= (1<<ii); }
if (b & (1<<ii) ) { returnint |= (1<<(ii+8));}
}
MCAValue[i] = returnint;
Int_t k=i*4+2;
a=MCAValue_block[k];
b=MCAValue_block[k+1];
returnint=0;
for (Int_t ii=0; ii<8; ii++) {
if (a & (1<<ii) ) { returnint |= (1<<ii); }
if (b & (1<<ii) ) { returnint |= (1<<(ii+8));}
}
MCAValue[i] = MCAValue[i]+returnint*65536;
//hmca[icha]->SetBinContent(i+1,returnint);
hmca[icha]->SetBinContent(i+1,MCAValue[i]);
}
//-----> done looping over all channels
hmca[icha]->SetBinContent(1,0.0);
hmca[icha]->SetBinContent(2,0.0);
hmca[icha]->SetBinContent(3,0.0);
cout<<" channel "<<icha<<" finished "<<endl;
}
//
//--> save histograms to output file
//
TFile* foutput = new TFile(output_histo_filename,"recreate");
foutput->cd();
for (Int_t i=0; i<nchannels; i++) {
hmca[i]->Write();
}
foutput->Close();
}