-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateGEMTree.C
More file actions
118 lines (80 loc) · 3.09 KB
/
CreateGEMTree.C
File metadata and controls
118 lines (80 loc) · 3.09 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
#include "TMath.h"
#include "TTree.h"
#include "TFile.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TRandom.h"
#include "stdio.h"
#include "stdlib.h"
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
#include <limits>
const double pi = 3.14159265;
const double mn = 1.674927471e-27; // in kg
const double hp = 6.62607004e-34; // in kg * m2/s
const double m2a = 1e+10; // unit to convert m in A
using namespace std;
//Usage: .L CreateGEMTree.C /CreateGEMRootFile()
void CreateGEMRootFile()
{
TTree* t=new TTree("ngem_ev","ngem_ev");
ULong64_t X0,X1,Y0,Y1,clusTX,clusTY,tof,t0,pixelX,pixelY;
double lambda;
// see below the description of the variables or the read_nGEM_data.h header file
t->Branch("X0",&X0,"X0/l"); // X position of pixel detected first
t->Branch("X1",&X1,"X1/l"); // X position of pixel detected last
t->Branch("Y0",&Y0,"Y0/l"); // Y position of pixel detected first
t->Branch("Y1",&Y1,"Y1/l"); // Y position of pixel detected last
t->Branch("clusTX",&clusTX,"clusTX/l"); // Integrated time of the cluster on the X side
t->Branch("clusTY",&clusTY,"clusTY/l"); // Integrated time of the cluster on the Y side
t->Branch("tof",&tof,"tof/l"); // Difference between T0 and detector timestamp
t->Branch("t0",&t0,"t0/l"); // T0 time, looks like a multiple of 3810 ns
t->Branch("pixelX",&pixelX,"pixelX/l"); // average pixel for cluster detection, X side
t->Branch("pixelY",&pixelY,"pixelY/l"); // average pixel for cluster detection, Y side
t->Branch("lambda",&lambda,"lambda/D"); // lambda value
gSystem->Exec("rm ngem.root");
TFile *rf=new TFile("ngem.root","new");
vector<string> row;
string line,word;
fstream fin;
fin.open("data_for_root.txt");
cout<<" "<<endl;
cout<<"Reading the data file..."<<endl;
while (!fin.eof())
{
row.clear();
// read an entire row and store it in a string variable 'line'
getline(fin, line);
// used for breaking words
stringstream s(line);
// read every column data of a row and store it in a string variable, 'word'
while (getline(s, word, '\t')){
// add all the column data of a row to a vector
row.push_back(word);
// cout<<"word ="<<word<<endl;
}
t0=stol(row[0]);
tof=stol(row[1]);
clusTX=stol(row[2]);
clusTY=stol(row[3]);
X0=stol(row[4]);
X1=stol(row[5]);
Y0=stol(row[6]);
Y1=stol(row[7]);
pixelX=stol(row[8]);
pixelY=stol(row[9]);
lambda = hp*tof/1e+6/mn/41500*m2a; // WISH
// cout<<"tof ="<<tof<<"posx ="<<posx<<endl;
t->Fill();
}
fin.close();
t->Write();
cout<<"Fill data tree...done"<<endl;
cout<<"The data tree has "<<t->GetEntries()<<" entries."<<endl;
cout<<" "<<endl;
rf->Close();
// ngem_ev->Draw("tof*6.62607004e-34/1e+6/1.674927471e-27/41500*1e+10")
}