-
Notifications
You must be signed in to change notification settings - Fork 0
/
integrate.C
47 lines (44 loc) · 1.74 KB
/
integrate.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
// Integrate waveforms in [min, max). If min, max are not specified,
// min = threshold crossing point - front
// max = downward zero crossing point + back
void integrate(int run=0, int ch=1, int min=0, int max=0,
int front=50, int back=10)
{
TFile *file = new TFile(Form("run/%d/wave%d.root",run,ch),"update");
TTree *t = (TTree*) file->Get("t");
int n, tt; float a, s[99999] = {0};
t->SetBranchAddress("s",&s); // waveform samples
t->SetBranchAddress("n",&n); // number of samples
t->SetBranchAddress("tt",&tt); // trigger position
TBranch *bint = t->Branch("a",&a,"a/F"); // area in [min, max)
TBranch *bmax = t->Branch("max",&max,"max/I");
TBranch *bmin = t->Branch("min",&min,"min/I");
bool search4boundaries=false; t->GetEntry(0);
if (min<=0 || max<=min || max>=n) { // if not specified correctly
if (tt==-1) { // external trigger, integration range must be specified
cout<<"run "<<run<<" is taken with external trigger, please use"<<endl;
cout<<"root npe.C'(int run,int channel,int min,int max)'\nto specify "
"integration range with 0 < min < max < number of samples"<<endl;
return;
} else { // internal trigger
search4boundaries=true;
}
}
int nevt=t->GetEntries();
cout<<"Processing "<<nevt<<" events..."<<endl;
for (int i=0; i<nevt; i++) {
t->GetEntry(i); if (i%5000==0) cout<<"Processing event "<<i<<endl;
if (search4boundaries) {
min=tt-front;
// search for downward zero crossing point
max=0;
for (int j=tt; j<n; j++) { if (s[j]<0) max=j+back; if (max>0) break; }
cout<<tt<<", "<<min<<", "<<max<<endl;
}
a=0; for (int j=min; j<max; j++) a+=s[j];
bint->Fill(); bmin->Fill(); bmax->Fill();
}
t->Write("",TObject::kOverwrite);
file->Close();
cout<<"File "<<file->GetName()<<" saved"<<endl;
}