16 #include "Math/DistFunc.h"
21 #include <TObjString.h>
26 #include <TTreeIndex.h>
42 return par[0] * TMath::Gaus(x[0], par[1], par[2]) + par[3];
47 TCanvas *
c =
new TCanvas(
"c",
"c", 800, 700);
49 h->GetXaxis()->SetTitle(
"v_{z}^{candidate} segments [cm]");
50 h->GetYaxis()->SetTitle(
"Counts");
51 h->GetYaxis()->SetTitleOffset(1.5);
52 h->SetMaximum(h->GetMaximum() * 1.2);
56 f->SetLineColor(kRed);
60 TLegend *
leg =
new TLegend(0.47, 0.8, 0.9, 0.92);
62 leg->SetBorderSize(0);
64 leg->SetTextSize(0.035);
65 leg->AddEntry((TObject *)0, Form(
"DCA < %.2f cm", dcacut),
"");
66 leg->AddEntry((TObject *)0, Form(
"#mu_{Gaussian} = %.2f #pm %.2f cm", f->GetParameter(1), f->GetParError(1)),
"");
68 c->SaveAs(Form(
"%s.pdf", plotname.Data()));
69 c->SaveAs(Form(
"%s.png", plotname.Data()));
74 int main(
int argc,
char *argv[])
77 gStyle->SetPalette(kThermometer);
79 bool IsData = (TString(argv[1]).Atoi() == 1) ?
true :
false;
80 int NevtToRun = TString(argv[2]).Atoi();
81 float avgVtxX = TString(argv[3]).Atof();
82 float avgVtxY = TString(argv[4]).Atof();
83 float dPhi_cut = TString(argv[5]).Atof();
84 float dca_cut = TString(argv[6]).Atof();
85 TString infilename = TString(argv[7]);
86 TString outfilename = TString(argv[8]);
87 TString demoplotpath = TString(argv[9]);
88 bool debug = (TString(argv[10]).Atoi() == 1) ?
true :
false;
89 bool makedemoplot = (TString(argv[11]).Atoi() == 1) ?
true :
false;
94 for (
int i = 0;
i < argc;
i++)
96 cout <<
"argv[" <<
i <<
"] = " << argv[
i] << endl;
101 system(Form(
"mkdir -p %s", demoplotpath.Data()));
103 vector<Hit *> INTTlayer1, INTTlayer2;
106 TFile *
f =
new TFile(infilename,
"READ");
107 TTree *
t = (TTree *)f->Get(
"EventTree");
108 t->BuildIndex(
"event");
109 TTreeIndex *
index = (TTreeIndex *)t->GetTreeIndex();
110 int event, NTruthVtx;
111 float TruthPV_trig_x, TruthPV_trig_y, TruthPV_trig_z, centrality_bimp, centrality_impactparam, centrality_mbd, centrality_mbdquantity;
112 vector<int> *ClusLayer = 0;
113 vector<float> *ClusX = 0, *ClusY = 0, *ClusZ = 0, *ClusPhiSize = 0, *ClusZSize = 0;
114 vector<uint8_t> *ClusLadderZId = 0, *ClusLadderPhiId = 0;
115 t->SetBranchAddress(
"event", &event);
118 t->SetBranchAddress(
"NTruthVtx", &NTruthVtx);
119 t->SetBranchAddress(
"TruthPV_trig_x", &TruthPV_trig_x);
120 t->SetBranchAddress(
"TruthPV_trig_y", &TruthPV_trig_y);
121 t->SetBranchAddress(
"TruthPV_trig_z", &TruthPV_trig_z);
122 t->SetBranchAddress(
"centrality_bimp", ¢rality_bimp);
123 t->SetBranchAddress(
"centrality_impactparam", ¢rality_impactparam);
126 t->SetBranchAddress(
"centrality_mbd", ¢rality_mbd);
127 t->SetBranchAddress(
"centrality_mbdquantity", ¢rality_mbdquantity);
131 t->SetBranchAddress(
"ClusLayer", &ClusLayer);
132 t->SetBranchAddress(
"ClusX", &ClusX);
133 t->SetBranchAddress(
"ClusY", &ClusY);
134 t->SetBranchAddress(
"ClusZ", &ClusZ);
135 t->SetBranchAddress(
"ClusPhiSize", &ClusPhiSize);
136 t->SetBranchAddress(
"ClusZSize", &ClusZSize);
137 t->SetBranchAddress(
"ClusLadderZId", &ClusLadderZId);
138 t->SetBranchAddress(
"ClusLadderPhiId", &ClusLadderPhiId);
140 TFile *
outfile =
new TFile(outfilename.Data(),
"RECREATE");
141 TTree *minitree =
new TTree(
"minitree",
"Minitree of reconstructed vertices");
144 for (
int ev = 0; ev < NevtToRun; ev++)
146 Long64_t local = t->LoadTree(index->GetIndex()[ev]);
149 cout <<
"event=" <<
event <<
" has a total of " << ClusLayer->size() <<
" clusters" << endl;
156 if ((ClusLayer->at(
ihit) < 3 || ClusLayer->at(
ihit) > 6) || (ClusLadderZId->at(
ihit) < 0 || ClusLadderZId->at(
ihit) > 3))
158 cout <<
"Cluster (layer, ladderZId) = (" << ClusLayer->at(
ihit) <<
"," << ClusLadderZId->at(
ihit) <<
") is not in the INTT acceptance. Exit and check." << endl;
162 if (ClusPhiSize->at(
ihit) >= 5)
165 int layer = (ClusLayer->at(
ihit) == 3 || ClusLayer->at(
ihit) == 4) ? 0 : 1;
168 float edge = (ClusLadderZId->at(
ihit) == 0 || ClusLadderZId->at(
ihit) == 2) ? 0.8 : 0.5;
172 INTTlayer1.push_back(hit);
174 INTTlayer2.push_back(hit);
177 cout <<
"# of clusters in inner layer (layer ID 3+4, after cluster phi size selection) = " << INTTlayer1.size() <<
", outer layer (layer ID 5+6) = " << INTTlayer2.size() << endl;
179 TH1F *hM_vtxzprojseg =
new TH1F(Form(
"hM_vtxzprojseg_ev%d", ev), Form(
"hM_vtxzprojseg_ev%d", ev), 2800, -70, 70);
180 int goodpaircount = 0;
181 for (
size_t i = 0;
i < INTTlayer1.size();
i++)
183 for (
size_t j = 0;
j < INTTlayer2.size();
j++)
185 if (fabs(
deltaPhi(INTTlayer1[
i]->Phi(), INTTlayer2[
j]->Phi())) > dPhi_cut)
190 float m = (INTTlayer2[
j]->posY() - INTTlayer1[
i]->posY()) / (INTTlayer2[
j]->posX() - INTTlayer1[
i]->posX());
191 float b = INTTlayer1[
i]->posY() - m * INTTlayer1[
i]->posX();
193 float dca = fabs(m * avgVtxX - avgVtxY + b) / sqrt(m * m + 1);
198 float rho1 = sqrt(pow((INTTlayer1[
i]->posX() - avgVtxX), 2) + pow((INTTlayer1[
i]->posY() - avgVtxY), 2));
199 float rho2 = sqrt(pow((INTTlayer2[
j]->posX() - avgVtxX), 2) + pow((INTTlayer2[
j]->posY() - avgVtxY), 2));
200 float z = INTTlayer1[
i]->posZ() - (INTTlayer2[
j]->posZ() - INTTlayer1[
i]->posZ()) / (rho2 - rho1) * rho1;
201 float edge1 = INTTlayer1[
i]->Edge().first - (INTTlayer2[
j]->Edge().second - INTTlayer1[
i]->Edge().first) / (rho2 - rho1) * rho1;
202 float edge2 = INTTlayer1[
i]->Edge().second - (INTTlayer2[
j]->Edge().first - INTTlayer1[
i]->Edge().second) / (rho2 - rho1) * rho1;
206 cout <<
"----------" << endl
207 <<
"Cluster pair (i,j) = (" <<
i <<
"," <<
j <<
"); position (x1,y1,z1,x2,y2,z2) mm =(" << INTTlayer1[
i]->posX() * 10. <<
"," << INTTlayer1[
i]->posY() * 10. <<
"," << INTTlayer1[
i]->posZ() * 10. <<
","
208 << INTTlayer2[
j]->posX() * 10. <<
"," << INTTlayer2[
j]->posY() * 10. <<
"," << INTTlayer2[
j]->posZ() * 10. <<
")" << endl;
209 cout <<
"Cluster [phi1 (deg),eta1,phi2(deg),eta2]=[" << INTTlayer1[
i]->Phi() *
radianstodegree <<
"," << INTTlayer1[
i]->Eta() <<
"," << INTTlayer2[
j]->Phi() *
radianstodegree <<
"," << INTTlayer2[
j]->Eta() <<
"]" << endl
210 <<
"delta phi (in degree) = " << fabs(
deltaPhi(INTTlayer1[
i]->Phi(), INTTlayer2[
j]->Phi())) *
radianstodegree <<
"-> pass dPhi selection (<" << dPhi_cut
211 <<
" rad)=" << ((fabs(
deltaPhi(INTTlayer1[
i]->Phi(), INTTlayer2[
j]->Phi())) < dPhi_cut) ? 1 : 0) << endl;
212 cout <<
"DCA cut = " << dca_cut <<
" [cm]; vertex candidate (center,edge1,edge2) = (" << z <<
"," << edge1 <<
"," << edge2 <<
"), difference = " << edge2 - edge1 << endl;
213 cout <<
"dca w.r.t (avgVtxX [cm], avgVtxY [cm]) (in mm) = " << dca * 10 << endl;
219 int bin1 = hM_vtxzprojseg->FindBin(edge1);
220 int bin2 = hM_vtxzprojseg->FindBin(edge2);
224 float bincenter = hM_vtxzprojseg->GetBinCenter(
ibin);
225 float binwidth = hM_vtxzprojseg->GetBinWidth(
ibin);
229 w = ((bincenter + 0.5 * binwidth) - edge1) / binwidth;
230 else if (
ibin == bin2)
231 w = (edge2 - (bincenter - 0.5 * binwidth)) / binwidth;
235 hM_vtxzprojseg->Fill(bincenter, w);
242 cout <<
"Number of entries in hM_vtxzprojseg = " << hM_vtxzprojseg->Integral(-1, -1) << endl;
243 cout <<
"Number of good pairs = " << goodpaircount << endl;
244 if (debug && !IsData)
245 cout <<
"Event " << ev <<
" (Truth PVx, Truth PVy, Truth PVz) = (" << TruthPV_trig_x <<
", " << TruthPV_trig_y <<
", " << TruthPV_trig_z <<
")" << endl;
248 float maxbincenter = hM_vtxzprojseg->GetBinCenter(hM_vtxzprojseg->GetMaximumBin());
267 TF1 *
f1 =
new TF1(
"gaus_fit",
gaus_func, maxbincenter - 10, maxbincenter + 10, 4);
268 f1->SetParameters(hM_vtxzprojseg->GetBinContent(hM_vtxzprojseg->GetMaximumBin()), hM_vtxzprojseg->GetBinCenter(hM_vtxzprojseg->GetMaximumBin()), 4, 0);
269 f1->SetParLimits(0, 0, 10000);
270 f1->SetParLimits(2, 0, 1000);
271 f1->SetParLimits(3, 0, 1000);
272 hM_vtxzprojseg->Fit(f1,
"NQ",
"", hM_vtxzprojseg->GetBinCenter(hM_vtxzprojseg->GetMaximumBin()) - 9, hM_vtxzprojseg->GetBinCenter(hM_vtxzprojseg->GetMaximumBin()) + 9);
273 f1->SetParameters(hM_vtxzprojseg->GetBinContent(hM_vtxzprojseg->GetMaximumBin()), hM_vtxzprojseg->GetBinCenter(hM_vtxzprojseg->GetMaximumBin()), 4, 0);
274 f1->SetParLimits(0, 0, 10000);
275 f1->SetParLimits(2, 0, 1000);
276 f1->SetParLimits(3, -20, 1000);
277 hM_vtxzprojseg->Fit(f1,
"NQ",
"", hM_vtxzprojseg->GetBinCenter(hM_vtxzprojseg->GetMaximumBin()) - 9, hM_vtxzprojseg->GetBinCenter(hM_vtxzprojseg->GetMaximumBin()) + 9);
278 float mean = f1->GetParameter(1);
279 float meanErr = f1->GetParError(1);
282 cout <<
"Event " << ev <<
" Reco PVz = " << mean <<
" +/- " << meanErr <<
" cm" << endl;
286 TString
pname = Form(
"%s/hM_vtxzprojseg_ev%d", demoplotpath.Data(),
event);
302 vtxdata.
PV_x = avgVtxX;
303 vtxdata.
PV_y = avgVtxY;