forked from FabianFri/ArCLight_3DScan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.C
119 lines (95 loc) · 3.57 KB
/
analysis.C
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
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#define CN 64
#define startch 36
#define endch 41
#define monch1
#define startMon 43
#define endMon 44
bool debug = 0;
//Float_t gain[] = {1040.26, 1148.56, 1103.742, 1115.02, 1036.44, 1085.66};
Float_t gain[] = {480,480,480,480,480,480};
Float_t mon_gain[] = {480,480};
TString data_path("/data/LRS/acl_teststand/3dscan/root_files/");
Float_t arr_sum(Float_t arr[], int n)
{
Float_t sum = 0; // initialize sum
// Iterate through all elements
// and add them to sum
for (int i = 0; i < n; i++)
sum += arr[i];
return sum;
}
void writeIntegral(const char* logfilename){
Float_t x,y,z;
char filename[30];
Float_t LY_adc[endch-startch+1];
Float_t LY_nph[endch-startch+1];
Float_t LY_mon_adc[2];
Float_t LY_mon_nph[2];
Float_t LY_tot_adc;
Float_t LY_tot_nph;
FILE *f_in;
if((f_in = fopen(logfilename,"r"))==NULL){
fprintf( stderr, "Error- Unable to open %s\n", logfilename);
exit(-1);
}
printf("Open %s\n",logfilename);
string out_filename = string(logfilename).substr(0,string(logfilename).size()-4) + string(".root");
TFile* f_out = new TFile(out_filename.c_str(),"RECREATE");
TTree *t_out = new TTree("t_out","t_out");
t_out->Branch("x",&x);
t_out->Branch("y",&y);
t_out->Branch("z",&z);
t_out->Branch("LY_adc",&LY_adc,"LY_adc[6]/F");
t_out->Branch("LY_nph",&LY_nph,"LY_nph[6]/F");
t_out->Branch("LY_mon_adc",&LY_adc,"LY_mon_adc[2]/F");
t_out->Branch("LY_mon_nph",&LY_nph,"LY_mon_nph[2]/F");
t_out->Branch("LY_tot_adc",&LY_tot_adc);
t_out->Branch("LY_tot_nph",&LY_tot_nph);
char buffer[256];
while(fgets(buffer,256,f_in)){
sscanf(buffer,"%f %f %f %s",&x,&y,&z,filename);
printf("x: %f y:%f z:%f fn:%s\n",x,y,z,filename);
TFile *f_light = new TFile(data_path +TString("rlog_")+ TString(filename) + TString(".root"),"READ");
if(f_light==0){
fprintf(stderr,"Error- Data file %s not found\n",filename);
exit(-1);
}
TTree *tr = (TTree*)f_light->Get("rlog");
for(int ch = 0; ch<(endch-startch+1); ch++){
Double_t max_bin = tr->GetMaximum(Form("integral.ch%02d>>h_temp",ch+startch));
tr->Draw(Form("integral.ch%02d>>h_temp(10000,0,max_bin)",ch+startch),Form("integral.ch%02d>0",ch+startch));
TH1F *h_temp = (TH1F*)gDirectory->Get("h_temp");
LY_adc[ch] = h_temp->GetMean();
//if(debug) printf("%f\n",LY_adc[ch]);
LY_nph[ch] = LY_adc[ch]/gain[ch];
}
//read monitor
//if(z==-99 || z==99){
// Double_t mon1 = h_temp->GetMean();
//}
LY_tot_adc = arr_sum(LY_adc,endch-startch+1);
LY_tot_nph = arr_sum(LY_nph,endch-startch+1);
if(z==-99 || z==99){
//Double_t mon1 = h_temp->GetMean();
for(int ch = startMon; ch<endMon; ch++){
Double_t max_bin_mon = tr->GetMaximum(Form("integral.ch%02d>>h_temp",ch));
tr->Draw(Form("integral.ch%02d>>h_temp2(10000,0,max_bin)",ch),Form("integral.ch%02d>0",ch));
TH1F *h_temp2 = (TH1F*)gDirectory->Get("h_temp2");
LY_mon_adc[ch-startMon] = h_temp2->GetMean();
//if(debug) printf("%f\n",LY_adc[ch]);
LY_mon_nph[ch-startMon] = LY_mon_adc[ch-startMon]/mon_gain[ch-startMon];
}
LY_tot_adc = arr_sum(LY_mon_adc,2);
LY_tot_nph = arr_sum(LY_mon_nph,2);
}
f_out->cd();
t_out->Fill();
//if(debug) printf("%f %f\n",LY_tot_adc,LY_tot_nph);
}
t_out->Write("t_out",TObject::kOverwrite);
f_out->Close();
}