-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeNiceTree.cxx
More file actions
163 lines (124 loc) · 3.76 KB
/
makeNiceTree.cxx
File metadata and controls
163 lines (124 loc) · 3.76 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "DsTOFConventions.h"
#include "RawDsTofHeader.h"
#include "TFile.h"
#include "TTree.h"
#include "TChain.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TH2.h"
#include "TColor.h"
#include "TMath.h"
#include "TStyle.h"
#include "TSystem.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
using namespace std;
string findFilename(string dirname, int itdc);
int main(int argc, char *argv[]){
Int_t run;
string baseDir;
if((argc!=2)&&(argc!=3)){
std::cerr << "Usage 1: " << argv[0] << " [irun] (basedir)" << std::endl;
return 1;
} else {
run = atoi(argv[1]);
if (argc==3) baseDir += argv[2];
else baseDir += whereIsMyTOFdata;
}
string dirname = Form("%s/run%d/", baseDir.c_str(), run);
string filename[2];
for (int itdc=0; itdc<2; itdc++){
filename[itdc] = findFilename(dirname, itdc+1);
}
if (filename[0]=="nothing" || filename[1]=="nothing"){
cout << "Could not find parsed files in directory " << dirname << endl;
} else {
cout << "Path to TDC1 parsed file " << filename[0] << endl;
cout << "Path to TDC2 parsed file " << filename[1] << endl;
}
string line;
for (int itdc=0; itdc<2; itdc++){
ifstream f((filename[itdc]).c_str());
Int_t channel1;
Int_t ticks1;
UInt_t unixTime1;
Double_t fakeTimeNs1;
Double_t fakeTimeNs2;
Double_t lastFakeTimeNs1;
Int_t countClock1=0;
Int_t count25k=0;
Int_t lastClockTdc=0;
Int_t tdcDiff;
string temp;
RawDsTofHeader *tof = NULL;
cout << "Writing output " << Form("%s/DsTOFtreeRun%d_tdc%d.root", dirname.c_str(), run, itdc+1) << endl;
TFile *fout = new TFile(Form("%s/DsTOFtreeRun%d_tdc%d.root", dirname.c_str(), run, itdc+1), "recreate");
TH1D *hClock = new TH1D("hClock", "", 100, -TMath::Power(2,21), TMath::Power(2,21));
TTree *tofTree = new TTree("tofTree","HPTPC Time Of Flight");
tofTree->Branch("tof", &tof);
if (f.is_open()){
while (getline (f,line)){
if (line.find("unix") != std::string::npos){
stringstream ss(line);
ss >> temp >> unixTime1;
continue;
}
stringstream ss(line);
ss >> channel1 >> temp >> ticks1;
if(channel1==0) {
count25k++;
hClock->Fill(ticks1-lastClockTdc);
if ((ticks1-lastClockTdc)<0) countClock1++;
lastClockTdc=ticks1;
fakeTimeNs1=count25k*40e3;
} else {
tdcDiff=ticks1-lastClockTdc;
if(tdcDiff<-400000) tdcDiff+=TMath::Power(2,21);
fakeTimeNs1 = count25k*40.e3 + tdcDiff*clockTicksNs;
fakeTimeNs2 = ( countClock1*TMath::Power(2, 21) +ticks1)*clockTicksNs;
// cout << fakeTimeNs1 << " " << fakeTimeNs2 << " " << fakeTimeNs1-fakeTimeNs2 << endl;
// cout << run << " " << channel1 << endl;
if(tof)
delete tof;
tof = new RawDsTofHeader();
tof->run=(Short_t)run;
tof->tdc=(Short_t)itdc+1;
tof->channel=(Short_t)channel1;
tof->ticks=ticks1;
tof->count25k=count25k;
tof->unixTime=unixTime1;
tof->fakeTimeNs=fakeTimeNs1;
tofTree->Fill();
}
}
tofTree->Write("tofTree");
hClock->Write("hClock");
fout->Close();
f.close();
}else{
cout << "Don't know file : " << filename[itdc] << endl;
}
cout << "DONE TDC " << itdc+1 << endl;
}
return 0;
}
string findFilename(string dirname, int itdc){
DIR *dp;
dirent *d;
if((dp = opendir(dirname.c_str())) == NULL)
perror("opendir");
while((d = readdir(dp)) != NULL){
if(!strcmp(d->d_name,".") || !strcmp(d->d_name,".."))
continue;
string temp = d->d_name;
if (temp.find(Form("parsed_%d_", itdc)) != std::string::npos){
if (temp.find(".root") != std::string::npos) continue;
else return dirname+"/"+temp;
}
}
return "nothing";
}