-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreadUpsTree.C
More file actions
321 lines (270 loc) · 11.5 KB
/
readUpsTree.C
File metadata and controls
321 lines (270 loc) · 11.5 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#include "TFile.h"
#include "TTree.h"
#include "TRandom.h"
#include "TCanvas.h"
#include <vector>
using namespace std;
const float elmass = 0.000510998910;
void readUpsTree(const Char_t *inputFile="test.root", Int_t cutSet = 0) {
TFile* fin = new TFile(inputFile,"READ");
//TFile *fsim = new TFile("simBB_0419_2eq6.root","READ");
//TFile *fsim = new TFile("simBB_0405_2e.root","READ");
TFile *fsim = new TFile("../upstree/simBB_0505_2e_m.root","READ");
//TFile *fsim = new TFile("simBB_0405_2eq20.root","READ");
//TFile *fsim = new TFile("simBB_0420_DYq6.root","READ");
//TFile *fsim = new TFile("simBB_0409_2eq15.root","READ");
TTree* upsTree = (TTree*)fin->Get("upsTree");
TTree* bbbar = (TTree*)fsim->Get("bbbar");
Float_t fMass = 0;
Int_t fCentrality = 0;
Int_t fSign = 0;
TTree* massTree = new TTree("massTree", "massTree");
massTree->Branch("fMass", &fMass, "fMass/F");
massTree->Branch("fCentrality", &fCentrality, "fCentrality/I");
massTree->Branch("fSign", &fSign, "fSign/I");
fin->cd();
int nEntries = upsTree->GetEntries();
cout << "upsTree has " << nEntries << " entries " << endl;
const int maxTracks = 100;
Int_t tEventId;
Int_t tEventRunId;
Float_t tEventTpcVx;
Float_t tEventTpcVy;
Float_t tEventTpcVz;
Float_t tEventVpdVz;
Int_t tEventCent9;
Int_t tEventCent16;
Int_t tEventRefMult;
Int_t tEventRefMultC;
Int_t tNElectrons;
Float_t tElePt[maxTracks];
Float_t tEleP[maxTracks];
Float_t tElePx[maxTracks];
Float_t tElePy[maxTracks];
Float_t tElePz[maxTracks];
Float_t tEleEta[maxTracks];
Int_t tEleCharge[maxTracks];
Int_t tEleNHits[maxTracks];
Float_t tEleNRat[maxTracks];
Int_t tEleNDedx[maxTracks];
Float_t tEleDca[maxTracks];
Float_t tEleDedx[maxTracks];
Float_t tEleNSigE[maxTracks];
Float_t tEleE[maxTracks];
Float_t tEleEcl[maxTracks];
Float_t tEleZDist[maxTracks];
Float_t tElePhiDist[maxTracks];
Float_t tEleR[maxTracks];
Int_t tEleTrig[maxTracks];
upsTree->SetBranchAddress("tEventId",&tEventId);
upsTree->SetBranchAddress("tEventRunId",&tEventRunId);
upsTree->SetBranchAddress("tEventTpcVx",&tEventTpcVx);
upsTree->SetBranchAddress("tEventTpcVy",&tEventTpcVy);
upsTree->SetBranchAddress("tEventTpcVz",&tEventTpcVz);
upsTree->SetBranchAddress("tEventVpdVz",&tEventVpdVz);
upsTree->SetBranchAddress("tEventCent9",&tEventCent9);
upsTree->SetBranchAddress("tEventCent16",&tEventCent16);
upsTree->SetBranchAddress("tEventRefMult",&tEventRefMult);
upsTree->SetBranchAddress("tEventRefMultC",&tEventRefMultC);
upsTree->SetBranchAddress("tNElectrons",&tNElectrons);
upsTree->SetBranchAddress("tElePt",tElePt);
upsTree->SetBranchAddress("tEleP",tEleP);
upsTree->SetBranchAddress("tElePx",tElePx);
upsTree->SetBranchAddress("tElePy",tElePy);
upsTree->SetBranchAddress("tElePz",tElePz);
upsTree->SetBranchAddress("tEleEta",tEleEta);
upsTree->SetBranchAddress("tEleCharge",tEleCharge);
upsTree->SetBranchAddress("tEleNHits",tEleNHits);
upsTree->SetBranchAddress("tEleNRat",tEleNRat);
upsTree->SetBranchAddress("tEleNDedx",tEleNDedx);
upsTree->SetBranchAddress("tEleDca",tEleDca);
upsTree->SetBranchAddress("tEleDedx",tEleDedx);
upsTree->SetBranchAddress("tEleNSigE",tEleNSigE);
upsTree->SetBranchAddress("tEleE",tEleE);
upsTree->SetBranchAddress("tEleEcl",tEleEcl);
upsTree->SetBranchAddress("tEleZDist",tEleZDist);
upsTree->SetBranchAddress("tElePhiDist",tElePhiDist);
upsTree->SetBranchAddress("tEleR",tEleR);
upsTree->SetBranchAddress("tEleTrig",tEleTrig);
//Float_t px[kMaxTrack];
TH1F* hEventVz = new TH1F("hEventVz","hEventVz",100,-30,30);
TH1F* hEleP = new TH1F("hEleP","",200,0,15);
TH1F* hIMun = new TH1F("hIMun","",200,0,20);
hIMun->Sumw2();
TH1F* hIMli = new TH1F("hIMli","",200,0,20);
hIMli->Sumw2();
TH1F* hRbg = new TH1F("hRbg","",400,0,20);
hRbg->Sumw2();
hIMmix = new TH1F("hIMmix","",200,0,20);
hIMmix->Sumw2();
hIMmixC = new TH2F("hIMmixC","",200,0,20,10,0,10);
hIMmixC->Sumw2();
TH1F* hUpsPt = new TH1F("hUpsPt","",200,0,20);
hUpsPt->Sumw2();
int ncuts = 8;
if (cutSet+1>ncuts) {
cout << "Invalid set of cuts was chosen! Setting to default." << endl;
cutSet = 0; }
//6 - optimised for p17lm y<1 (sig)
//7 - optimised for p17lm y<.5 (sig)
const float cutVzTpc[] = {30., 30., 30., 30., 30., 30., 30., 30,}; //vertex
const float cutVzDif[] = {4., 4., 4., 4., 4., 4., 4., 4.};
const int cutNHits[] = {20, 30, 25, 20, 20, 20, 20, 20}; //nhits
const float cutNRat[] = {0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52};
const int cutNDedx[] = {10, 10, 10, 10, 10, 10, 10, 10};
const float cutNsigL[] = {-1.5, -1.5, -1.5, -1.5, -1.5, -1.5, -1.4, -1.3};
const float cutNsigT[] = {3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0};
const float cutEta[] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
const float cutEpL[] = {0.75, 0.75, 0.3, 0.3, 0.75, 0.75, 0.65, 0.70};
const float cutEpT[] = {1.5, 1.5, 1.8, 1.8, 1.5, 1.5, 1.6, 1.4};
const float cutR[] = {0.025, 0.025, 0.025, 0.03, 0.025, 0.025, 0.026, 0.026};
const float cutPlow[] = {3.25, 3.5, 3.5, 3.0, 3.5, 3.5, 3.5, 3.5};
const float cutDca[] = {0.75, 0.75, 1.5, 1.5, 0.75, 0.75, 3.0, 3.0};
const float cutPlead[] = {4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5};
const float cutPairY[] = {1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 0.5};
const float cutPairPt[] = {10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10., 10.};
// make rbg histo
TString bbcuts = Form("eleGlDca<%f&&posGlDca<%f&&",cutDca[cutSet],cutDca[cutSet]);
bbcuts += Form("elePrP>%f&&posPrP>%f&&",cutPlow[cutSet],cutPlow[cutSet]);
bbcuts += Form("elePrEta>-%f&&posPrEta>-%f&&",cutEta[cutSet],cutEta[cutSet]);
bbcuts += Form("elePrEta<%f&&posPrEta<%f&&",cutEta[cutSet],cutEta[cutSet]);
bbcuts += Form("(elePrP>%f||posPrP>%f)&&",cutPlead[cutSet],cutPlead[cutSet]);
bbcuts += Form("motherPt<%f&&",cutPairPt[cutSet]);
bbcuts += Form("motherY>-%f&&",cutPairY[cutSet]);
bbcuts += Form("motherY<%f",cutPairY[cutSet]);
//bbcuts += Form("&&motherY<%f",-10.);
bbbar->Draw("motherM>>hRbg",bbcuts.Data(),"");
//"eleGlDca<0.75&&posGlDca<0.75&&elePrP>3.25&&posPrP>3.25&&elePrEta<1.0&&elePrEta>-1.0&&posPrEta<1.0&&posPrEta>-1.0&&(elePrP>4.5||posPrP>4.5)&&motherPt<10&&motherY<1.0&&motherY>-1.0")")
cout << "done with rbg" << endl;
// mixing events
int mixCounter = 0;
int mixSaved = 5000;
vector<TLorentzVector> trigElectrons;
vector<Float_t> trigElectronsVz;
vector<Int_t> trigElectronsC;
vector<TLorentzVector> allElectrons;
vector<Float_t> allElectronsVz;
vector<Int_t> allElectronsC;
//nEntries = 50000;
for (int iEv = 0; iEv < nEntries; ++iEv)
{
upsTree->GetEntry(iEv);
hEventVz->Fill(tEventTpcVz);
//event cuts
if (fabs(tEventTpcVz) > cutVzTpc[cutSet]) continue;
if (fabs(tEventTpcVz-tEventVpdVz) > cutVzDif[cutSet]) continue;
//if (tEventCent9 > 4) continue;
for (int iTr1 = 0; iTr1 < tNElectrons; ++iTr1)
{
//track cuts
if (tEleNHits[iTr1] < cutNHits[cutSet]) continue;
if (tEleNRat[iTr1] < cutNRat[cutSet]) continue;
//if (tEleNDedx[iTr1] < cutNdDedx[cutSet]) continue;
if (tEleNSigE[iTr1] < cutNsigL[cutSet]) continue;
if (tEleNSigE[iTr1] > cutNsigT[cutSet]) continue;
if (fabs(tEleEta[iTr1]) > cutEta[cutSet]) continue;
if (tEleEcl[iTr1]/tEleP[iTr1] < cutEpL[cutSet]) continue;
if (tEleEcl[iTr1]/tEleP[iTr1] > cutEpT[cutSet]) continue;
if (tEleR[iTr1] > cutR[cutSet]) continue;
if (tEleP[iTr1] < cutPlow[cutSet]) continue;
if (tEleDca[iTr1] > cutDca[cutSet]) continue;
hEleP->Fill(tEleP[iTr1]);
for (int iTr2 = iTr1+1; iTr2 < tNElectrons; ++iTr2)
{
//partner cuts
if (tEleNHits[iTr2] < cutNHits[cutSet]) continue;
if (tEleNRat[iTr2] < cutNRat[cutSet]) continue;
//if (tEleNDedx[iTr2] < cutNDedx[cutSet]) continue;
if (tEleNSigE[iTr2] < cutNsigL[cutSet]) continue;
if (tEleNSigE[iTr2] > cutNsigT[cutSet]) continue;
if (fabs(tEleEta[iTr2]) > cutEta[cutSet]) continue;
if (tEleEcl[iTr2]/tEleP[iTr2] < cutEpL[cutSet]) continue;
if (tEleEcl[iTr2]/tEleP[iTr2] > cutEpT[cutSet]) continue;
if (tEleR[iTr2] > cutR[cutSet]) continue;
if (tEleP[iTr2] < cutPlow[cutSet]) continue;
if (tEleDca[iTr2] > cutDca[cutSet]) continue;
//pair cuts
if (!(tEleTrig[iTr1]%2)&&!(tEleTrig[iTr2]%2)) continue;
TLorentzVector* tl1 = new TLorentzVector(tElePx[iTr1],tElePy[iTr1],tElePz[iTr1],sqrt(tEleP[iTr1]*tEleP[iTr1]+elmass*elmass));
TLorentzVector* tl2 = new TLorentzVector(tElePx[iTr2],tElePy[iTr2],tElePz[iTr2],sqrt(tEleP[iTr2]*tEleP[iTr2]+elmass*elmass));
TLorentzVector* q = new TLorentzVector(*tl1+*tl2);
if (mixCounter < 2*mixSaved) {
if ((mixCounter+1)%2) {
if (tEleTrig[iTr1]%2) trigElectrons.push_back(*tl1);
else if (tEleTrig[iTr2]%2) trigElectrons.push_back(*tl2);
trigElectronsVz.push_back(tEventTpcVz);
trigElectronsC.push_back(tEventCent9); }
if (mixCounter%2) {
if (!tEleTrig[iTr1]%2) allElectrons.push_back(*tl1);
else if (!tEleTrig[iTr2]%2) allElectrons.push_back(*tl2);
allElectronsVz.push_back(tEventTpcVz);
allElectronsC.push_back(tEventCent9); }
mixCounter++;
}
if (tEleP[iTr1]<cutPlead[cutSet] &&tEleP[iTr2]<cutPlead[cutSet]) continue;
if (q->M() < 0.2) continue;
if (q->Perp() > cutPairPt[cutSet]) continue;
if (fabs(q->Rapidity()) > cutPairY[cutSet]) continue;
fMass = q->M();
fCentrality = tEventCent9;
fSign = tEleCharge[iTr1]*tEleCharge[iTr2];
massTree->Fill();
if (tEleCharge[iTr1]*tEleCharge[iTr2] < 0) {
hIMun->Fill(q->M());
if (q->M() < 9.9 && q->M() > 8.9) hUpsPt->Fill(q->Perp());}
else {
hIMli->Fill(q->M()); }
}
}
}
cout << "done reading tree" << endl;
// do mixed events mass here
for (int iET = 0; iET < trigElectrons.size(); ++iET)
{
TLorentzVector* p1 = new TLorentzVector(trigElectrons[iET]);
for (int iEA = 0; iEA < allElectrons.size(); ++iEA)
{
TLorentzVector* p2 = new TLorentzVector(allElectrons[iEA]);
if (fabs(trigElectronsVz[iET]-allElectronsVz[iEA])>7) continue;
if (trigElectronsC[iET] != allElectronsC[iEA]) continue;
TLorentzVector* q = new TLorentzVector(*p1 + *p2);
if (p1->P() < cutPlead[cutSet] && p2->P() < cutPlead[cutSet]) continue;
if (q->M() < 0.2) continue;
if (q->Perp() > cutPairPt[cutSet]) continue;
if (fabs(q->Rapidity()) > cutPairY[cutSet]) continue;
hIMmix->Fill(q->M());
hIMmixC->Fill(q->M(),trigElectronsC[iET]);
}
}
cout << "done mixing" << endl;
int abin = hIMli->FindBin(5.0);
int bbin = hIMli->FindBin(15.0);
hIMmix->Scale((float)hIMli->Integral(abin,bbin)/hIMmix->Integral(abin,bbin));
TFile *frbg = new TFile("hRbg.root","RECREATE");
frbg->cd();
hRbg->Write();
frbg->Close();
TFile* fmass = new TFile("masstree.root","RECREATE");
fmass->cd();
hIMmixC->Write();
massTree->Write();
fmass->Close();
hIMun->Draw();
hIMli->SetLineColor(kRed);
hIMli->Draw("same");
hIMmix->SetLineColor(kGreen+2);
hIMmix->Draw("same");
new TCanvas;
hUpsPt->Draw();
int a = hIMun->FindBin(8.9);
int b = hIMun->FindBin(9.9);
float un = hIMun->Integral(a,b);
float li = hIMli->Integral(a,b);
cout << "un " << un << " li " << li << " ups " << un-li << " s/b " << (un-li)/li << " sig " << (un-li)/sqrt(un) << endl;
new TCanvas;
hIMun->Add(hIMli,-1);
//hIMun->Add(hIMmix,-1);
hIMun->Rebin();
hIMun->GetXaxis()->SetRangeUser(5.,15.);
hIMun->Draw();
}