-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo.C
197 lines (158 loc) · 4.64 KB
/
demo.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
void makeTree(Int_t nevents = 100)
{
TFile *outFile = TFile::Open("outFile.root", "RECREATE");
outFile->cd();
TTree *outT = new TTree("jettyTree", "STAR Pico Jetty Tree");
//Int_t split = 99;
Int_t split = 2;
Int_t bsize = 64000;
TStarJetPicoEvent *event = 0;
outT->Branch("Jetty", "TStarJetPicoEvent", &event, bsize, split);
TStarJetPicoPrimaryTrack pTrack;
TStarJetPicoMatchedTower mTower;
TStarJetPicoTower emcalTower;
TRandom rndm;
Int_t ntracks = 0;
for (Int_t iev = 0; iev < nevents; iev++)
{
event = new TStarJetPicoEvent();
// set the stuff for the event header
event->GetHeader()->SetEventId(iev);
// get the primary tracks filled
ntracks = rndm.Rndm() * 100;
//for (Int_t it = 0; it < ntracks; it++)
//for (Int_t it = 0; it < 5; it++)
for (Int_t it = 0; it < ntracks; it++)
{
//pTrack.SetPx(ntracks / 100.);
pTrack.SetPx((1.*iev)/nevents);
event->AddPrimaryTrack(&pTrack);
}
// fill the matched towers
ntracks = rndm.Rndm() * 1000;
for (Int_t it = 0; it < ntracks; it++)
{
//mTower.SetPx(ntracks / 100.);
mTower.SetPx(rndm.Rndm() * 10.);
mTower.SetPy(rndm.Rndm() * 10.);
mTower.SetPz(rndm.Rndm() * 10.);
mTower.SetTowerEnergy(rndm.Rndm() * 10.);
event->AddMatchedTower(&mTower);
}
// fill the all emcal towers
ntracks = rndm.Rndm() * 100;
for (Int_t it = 0; it < ntracks; it++)
{
emcalTower.SetId(ntracks);
emcalTower.SetEnergy(ntracks / 100.);
event->AddTower(&emcalTower);
}
outT->Fill();
//TStarJetPicoEvent::Reset();
delete event;
}
outT->Write();
outFile->cd();
outFile->Close();
delete outFile;
outFile = 0;
}
void readTree(Int_t nevents = 100)
{
TFile *inFile = TFile::Open("outFile.root");
inFile->cd();
TTree *outT = inFile->Get("jettyTree");
TStarJetPicoEvent *event = new TStarJetPicoEvent();
TBranch *branch = outT->GetBranch("Jetty");
branch->SetAddress(&event);
Int_t ievents = outT->GetEntries();
TStarJetPicoPrimaryTrack *pTrack = 0;
TStarJetPicoMatchedTower *mTower = 0;
TStarJetPicoTower *emcalTower = 0;
TH1F *hpxPT = new TH1F("hpxPT", "hpxPT;px;counts", 100, 0, 1);
TH1F *hpxMT = new TH1F("hpxMT", "hpxMT;px;counts", 100, 0, 1);
TH1F *hpxEMCT = new TH1F("hpxEMCT", "hpxEMCT;px;counts", 100, 0, 1);
for (Int_t i = 0; i<ievents; i++)
{
outT->GetEvent(i);
for (Int_t ntrack = 0;
ntrack < event->GetHeader()->GetNOfPrimaryTracks();
ntrack++)
{
TStarJetPicoPrimaryTrack *ptrack = event->GetPrimaryTrack(ntrack);
hpxPT->Fill(ptrack->GetPx());
}
for (Int_t ntrack = 0;
ntrack < event->GetHeader()->GetNOfMatchedTowers();
ntrack++)
{
TStarJetPicoMatchedTower *mtower = event->GetMatchedTower(ntrack);
hpxMT->Fill(mtower->GetPx());
}
for (Int_t ntrack = 0;
ntrack < event->GetHeader()->GetNOfEMCALTowers();
ntrack++)
{
TStarJetPicoTower *tower = event->GetTower(ntrack);
hpxEMCT->Fill(tower->GetEnergy());
}
event->Clear();
}
delete event;
TCanvas *tc = new TCanvas("tc", "tc");
tc->Divide(2,2);
tc->cd(1);
hpxPT->Draw();
tc->cd(2);
hpxMT->Draw();
tc->cd(3);
hpxEMCT->Draw();
}
void readTreeAnother(Int_t nevents = 100)
{
TFile *inFile = TFile::Open("outFile.root");
inFile->cd();
TTree *outT = inFile->Get("jettyTree");
TStarJetPicoEvent *event = new TStarJetPicoEvent();
TBranch *branch = outT->GetBranch("Jetty");
branch->SetAddress(&event);
Int_t ievents = outT->GetEntries();
TStarJetPicoPrimaryTrack *pTrack = 0;
TStarJetPicoMatchedTower *mTower = 0;
TStarJetPicoTower *emcalTower = 0;
TH1F *hpxPT = new TH1F("hpxPT", "hpxPT;px;counts", 100, 0, 1);
TH1F *hpxMT = new TH1F("hpxMT", "hpxMT;px;counts", 100, 0, 1);
TH1F *hpxEMCT = new TH1F("hpxEMCT", "hpxEMCT;px;counts", 100, 0, 1);
for (Int_t i = 0; i<ievents; i++)
{
outT->GetEvent(i);
Int_t iptrack = 0;
TStarJetPicoPrimaryTrack *ptrack = 0;
while ((ptrack = event->GetPrimaryTrack(iptrack++)) != 0)
{
hpxPT->Fill(ptrack->GetPx());
}
Int_t imtower = 0;
TStarJetPicoMatchedTower *mtower = 0;
while ((mtower = event->GetMatchedTower(imtower++)) != 0)
{
hpxMT->Fill(mtower->GetPx());
}
Int_t itower = 0;
TStarJetPicoTower *tower = 0;
while ((tower = event->GetTower(itower++)) != 0)
{
hpxEMCT->Fill(tower->GetEnergy());
}
event->Clear();
}
delete event;
TCanvas *tc = new TCanvas("tc_2", "tc_2");
tc->Divide(2,2);
tc->cd(1);
hpxPT->Draw();
tc->cd(2);
hpxMT->Draw();
tc->cd(3);
hpxEMCT->Draw();
}