BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
GrXtCalib.cpp
Go to the documentation of this file.
1#include "include/GrXtCalib.h"
2#include "include/fun.h"
3
4#include <cmath>
5
6#include "TMinuit.h"
7#include "TF1.h"
8
10 m_maxNhit = 5000;
11 m_nMaxEd = 1000;
12 for(int lay=0; lay<NLAYER; lay++){
13 if(lay<8) m_tEd[lay] = 200.0;
14 else m_tEd[lay] = 300.0;
15 }
16 cout << "Calibration type: GrXtCalib" << endl;
17}
18
20}
21
22void GrXtCalib::init(TObjArray* hlist, MdcCosGeom* pGeom){
23 CalibBase::init(hlist, pGeom);
24
25 m_fdXt = new TFolder("mfdxt","fdxt");
26 hlist->Add(m_fdXt);
27
28 m_haxis = new TH2F("axis", "", 50, 0, 300, 50, 0, 9);
29 m_haxis -> SetStats(0);
30 m_fdXt -> Add(m_haxis);
31
32 char hname[200];
33 for(int lay=0; lay<NLAYER; lay++){
34 for(int iEntr=0; iEntr<NENTRXT; iEntr++){
35 for(int lr=0; lr<NLR; lr++){
36 m_nhitIn[lay][iEntr][lr] = 0;
37 m_nhitEd[lay][iEntr][lr] = 0;
38
39 sprintf(hname, "mgrXt%02d_%02d_lr%01d", lay, iEntr, lr);
40 m_grxt[lay][iEntr][lr] = new TGraph();
41 m_grxt[lay][iEntr][lr] -> SetName(hname);
42 m_grxt[lay][iEntr][lr] -> SetMarkerStyle(10);
43 m_grxt[lay][iEntr][lr] -> SetLineColor(10);
44 m_fdXt -> Add(m_grxt[lay][iEntr][lr]);
45 }
46 }
47 }
48}
49
50void GrXtCalib::mergeHist(TFile* fhist){
52
53 double tdr, doca;
54 char hname[200];
55 TFolder* fd = (TFolder*)fhist->Get("fdXtGr");
56 for(int lay=0; lay<NLAYER; lay++){
57 for(int iEntr=0; iEntr<NENTRXT; iEntr++){
58 for(int lr=0; lr<NLR; lr++){
59 if((m_nhitIn[lay][iEntr][lr] > m_maxNhit) && (m_nhitEd[lay][iEntr][lr] > m_nMaxEd)) continue;
60
61 sprintf(hname, "grXt%02d_%02d_lr%01d", lay, iEntr, lr);
62 TGraph* gr = (TGraph*)fd->FindObjectAny(hname);
63 int nPoint = gr->GetN();
64 for(int i=0; i<nPoint; i++){
65 gr->GetPoint(i, tdr, doca);
66 if((tdr < m_tEd[lay]) && (m_nhitIn[lay][iEntr][lr] <= m_maxNhit)){
67 int np = m_grxt[lay][iEntr][lr]->GetN();
68 m_grxt[lay][iEntr][lr]->SetPoint(np, tdr, doca);
69 m_nhitIn[lay][iEntr][lr]++;
70 } else if((tdr >= m_tEd[lay]) && (m_nhitEd[lay][iEntr][lr] <= m_nMaxEd)){
71 int np = m_grxt[lay][iEntr][lr]->GetN();
72 m_grxt[lay][iEntr][lr]->SetPoint(np, tdr, doca);
73 m_nhitEd[lay][iEntr][lr]++;
74 }
75 }
76 }
77 }
78 }
79}
80
81void GrXtCalib::calib(MdcCalibConst* calconst, TObjArray* newXtList, TObjArray* r2tList){
82 CalibBase::calib(calconst, newXtList, r2tList);
83
84 int ord;
85 double xtpar[NLAYER][NENTRXT][NLR][8];
86 TF1* fxtDr = new TF1("fxtDr", xtFitFun, 0, 300, 6);
87 TF1* fxtEd = new TF1("fxtEd", xtFitEdge, 150, 500, 1);
88 if(1 == gfixXtC0) fxtDr -> FixParameter(0, 0);
89
90 for(int lay=0; lay<NLAYER; lay++){
91 for(int iEntr=0; iEntr<NENTRXT; iEntr++){
92 for(int lr=0; lr<NLR; lr++){
93 m_fgFit[lay][iEntr][lr] = false;
94 if(0 == gFgCalib[lay]) continue;
95
96 if(m_nhitIn[lay][iEntr][lr] > 1000){
97 Tmax = calconst -> getXtpar(lay, iEntr, lr, 6);
98
99 m_grxt[lay][iEntr][lr] -> Fit("fxtDr", "Q+", "", 0, Tmax);
100 for(ord=0; ord<6; ord++){
101 xtpar[lay][iEntr][lr][ord] = fxtDr->GetParameter(ord);
102 }
103 xtpar[lay][iEntr][lr][6] = Tmax;
104
105 Dmax = 0.0;
106 for(ord=0; ord<6; ord++) Dmax += xtpar[lay][iEntr][lr][ord] * pow(Tmax, ord);
107
108 if(m_nhitEd[lay][iEntr][lr] > 300){
109 m_grxt[lay][iEntr][lr] -> Fit("fxtEd", "Q+", "", Tmax, Tmax+300);
110 xtpar[lay][iEntr][lr][7] = fxtEd->GetParameter(0);
111 if(xtpar[lay][iEntr][lr][7] < 0.0) xtpar[lay][iEntr][lr][7] = 0.0;
112 } else{
113 xtpar[lay][iEntr][lr][7] = 0.0;
114 }
115
116 m_fgFit[lay][iEntr][lr] = true;
117 }
118
119 } // end of lr loop
120 } // end of entrance angle loop
121 } // end of layer loop
122
123 ofstream fxtlog("xtlog");
124 for(int lay=0; lay<NLAYER; lay++){
125 for(int iEntr=0; iEntr<NENTRXT; iEntr++){
126 for(int lr=0; lr<NLR; lr++){
127 fxtlog << setw(3) << lay << setw(3) << iEntr << setw(3) << lr;
128
129 int fgUpdate = -1;
130 if(m_fgFit[lay][iEntr][lr]){
131 fgUpdate = 1;
132 for(ord=0; ord<8; ord++) calconst->resetXtpar(lay, iEntr, lr, ord, xtpar[lay][iEntr][lr][ord]);
133 } else{
134 int iEntrNew = findXtEntr(lay, iEntr, lr);
135 if(-1 != iEntrNew){
136 fgUpdate = 2;
137 for(ord=0; ord<8; ord++){
138 calconst->resetXtpar(lay, iEntr, lr, ord, xtpar[lay][iEntrNew][lr][ord]);
139 }
140 }
141 }
142 fxtlog << setw(3) << fgUpdate;
143 for(ord=0; ord<8; ord++){
144 double par = calconst -> getXtpar(lay, iEntr, lr, ord);
145 if(6==ord) fxtlog << setw(9) << par;
146 else fxtlog << setw(14) << par;
147 }
148 fxtlog << endl;
149 }
150 }
151 }
152 fxtlog.close();
153
154 cout << "Xt update finished. File xtlog was written." << endl;
155
156 renameHist();
157 delete fxtDr;
158 delete fxtEd;
159}
160
161void GrXtCalib::renameHist(){
162 char hname[200];
163 m_fdXt->SetName("fdXtGr");
164 for(int lay=0; lay<NLAYER; lay++){
165 for(int iEntr=0; iEntr<NENTRXT; iEntr++){
166 for(int lr=0; lr<NLR; lr++){
167 sprintf(hname, "grXt%02d_%02d_lr%01d", lay, iEntr, lr);
168 m_grxt[lay][iEntr][lr] -> SetName(hname);
169 }
170 }
171 }
172}
173
174int GrXtCalib::findXtEntr(int lay, int iEntr, int lr) const {
175 int id0 = 8;
176 int id1 = 9;
177 int idmax = 17;
178 int entrId = -1;
179 if(iEntr <= id0){
180 int id = -1;
181 for(int i=iEntr; i<=id0; i++){
182 if(m_fgFit[lay][i][lr]){
183 id = i;
184 break;
185 }
186 }
187 if(-1 != id) entrId = id;
188 else{
189 for(int i=iEntr; i>=0; i--){
190 if(m_fgFit[lay][i][lr]){
191 id = i;
192 break;
193 }
194 }
195 entrId = id;
196 }
197 } else{
198 int id = -1;
199 for(int i=iEntr; i>=id1; i--){
200 if(m_fgFit[lay][i][lr]){
201 id = i;
202 break;
203 }
204 }
205 if(-1 != id) entrId = id;
206 else{
207 for(int i=iEntr; i<idmax; i++){
208 if(m_fgFit[lay][i][lr]){
209 id = i;
210 break;
211 }
212 }
213 entrId = id;
214 }
215 }
216 if(-1 == entrId){
217 cout << "find EntrId error " << "layer " << lay << " iEntr " << iEntr << " lr " << lr << endl;
218 }
219
220 return entrId;
221}
gr Fit("g1","R")
TGraph * gr
Double_t xtFitEdge(Double_t *x, Double_t par[])
Double_t xtFitFun(Double_t *x, Double_t par[])
virtual void init(TObjArray *hlist, MdcCosGeom *pGeom)=0
Definition: CalibBase.cpp:14
virtual void mergeHist(TFile *fhist)=0
Definition: CalibBase.cpp:365
virtual void calib(MdcCalibConst *calconst, TObjArray *newXtList, TObjArray *r2tList)=0
Definition: CalibBase.cpp:711
void calib(MdcCalibConst *calconst, TObjArray *newXtList, TObjArray *r2tList)
Definition: GrXtCalib.cpp:81
void init(TObjArray *hlist, MdcCosGeom *pGeom)
Definition: GrXtCalib.cpp:22
void mergeHist(TFile *fhist)
Definition: GrXtCalib.cpp:50
void resetXtpar(int lay, int entr, int lr, int order, double val)
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
gr1 SetLineColor(1)
gr1 SetMarkerStyle(8)
mg Add(gr3)