BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
GrXtMdcCalib.cxx
Go to the documentation of this file.
2
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/IMessageSvc.h"
5#include "GaudiKernel/StatusCode.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/Bootstrap.h"
8
9#include <iostream>
10#include <fstream>
11#include <iomanip>
12#include <cstring>
13#include <cmath>
14
15#include "TF1.h"
16
17using namespace std;
18
19double GrXtMdcCalib::DMAX;
20double GrXtMdcCalib::TMAX;
21
23 m_maxNhit = 5000;
24 m_fgIni = false;
25}
26
28}
29
31 cout << "~GrXtMdcCalib" << endl;
32 for(int lay=0; lay<MdcCalNLayer; lay++){
33 for(int iEntr=0; iEntr<MdcCalNENTRXT; iEntr++){
34 for(int iLR=0; iLR<MdcCalLR; iLR++){
35 delete m_grxt[lay][iEntr][iLR];
36 }
37 }
38 }
39 delete m_haxis;
40 delete m_fdXt;
41
43}
44
45void GrXtMdcCalib::initialize(TObjArray* hlist, IMdcGeomSvc* mdcGeomSvc,
46 IMdcCalibFunSvc* mdcFunSvc, IMdcUtilitySvc* mdcUtilitySvc) {
47 IMessageSvc* msgSvc;
48 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
49 MsgStream log(msgSvc, "GrXtMdcCalib");
50 log << MSG::INFO << "GrXtMdcCalib::initialize()" << endreq;
51
52 m_hlist = hlist;
53 m_mdcGeomSvc = mdcGeomSvc;
54 m_mdcFunSvc = mdcFunSvc;
55 m_mdcUtilitySvc = mdcUtilitySvc;
56
57 MdcCalib::initialize(m_hlist, m_mdcGeomSvc, m_mdcFunSvc, m_mdcUtilitySvc);
58
59 int lay;
60 int iLR;
61 int iEntr;
62 char hname[200];
63
64 m_fdXt = new TFolder("fdXtGr", "fdXtGr");
65 m_hlist -> Add(m_fdXt);
66
67 m_haxis = new TH2F("axis", "", 50, 0, 300, 50, 0, 9);
68 m_haxis -> SetStats(0);
69 m_fdXt -> Add(m_haxis);
70
71 for(lay=0; lay<MdcCalNLayer; lay++){
72 for(iEntr=0; iEntr<MdcCalNENTRXT; iEntr++){
73 for(iLR=0; iLR<MdcCalLR; iLR++){
74 m_nhit[lay][iEntr][iLR] = 0;
75
76 sprintf(hname, "grXt%02d_%02d_lr%01d", lay, iEntr, iLR);
77 m_grxt[lay][iEntr][iLR] = new TGraph();
78 m_grxt[lay][iEntr][iLR] -> SetName(hname);
79 m_grxt[lay][iEntr][iLR] -> SetMarkerStyle(10);
80 m_grxt[lay][iEntr][iLR] -> SetLineColor(10);
81 m_fdXt -> Add(m_grxt[lay][iEntr][iLR]);
82 }
83 }
84 }
85}
86
88 IMessageSvc* msgSvc;
89 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
90 MsgStream log(msgSvc, "GrXtMdcCalib");
91 log << MSG::DEBUG << "GrXtMdcCalib::fillHist()" << endreq;
92
93 MdcCalib::fillHist(event);
94
95 // get EsTimeCol
96 bool esCutFg = event->getEsCutFlag();
97 if( ! esCutFg ) return -1;
98
99 int i;
100 int k;
101 int lay;
102 int iLR;
103 int iEntr;
104
105 double dr;
106 double dz;
107 double doca;
108 double tdr;
109 double resi;
110 double entrance;
111
112 int nhitlay;
113 bool fgHitLay[MdcCalNLayer];
114 bool fgTrk;
115
116 if(! m_fgIni){
117 for(lay=0; lay<MdcCalNLayer; lay++){
118 if(lay < 8) m_docaMax[lay] = m_param.maxDocaInner;
119 else m_docaMax[lay] = m_param.maxDocaOuter;
120 }
121 m_fgIni = true;
122 }
123
124 MdcCalRecTrk* rectrk;
125 MdcCalRecHit* rechit;
126
127 int nhit;
128 int ntrk = event -> getNTrk();
129 for(i=0; i<ntrk; i++){
130 fgTrk = true;
131 rectrk = event->getRecTrk(i);
132 nhit = rectrk -> getNHits();
133
134 // dr cut
135 dr = rectrk->getDr();
136 if(fabs(dr) > m_param.drCut) continue;
137
138 // dz cut
139 dz = rectrk->getDz();
140 if(fabs(dz) > m_param.dzCut) continue;
141
142 for(lay=0; lay<MdcCalNLayer; lay++){
143 fgHitLay[lay] = false;
144 }
145
146 for(k=0; k<nhit; k++){
147 rechit = rectrk -> getRecHit(k);
148 lay = rechit -> getLayid();
149 doca = rechit -> getDocaInc();
150 resi = rechit -> getResiInc();
151 fgHitLay[lay] = true;
152
153// if( (fabs(doca) > m_docaMax[lay]) ||
154// (fabs(resi) > m_param.resiCut[lay]) ){
155// fgTrk = false;
156// }
157 }
158 if(! fgTrk) continue;
159
160 nhitlay = 0;
161 for(lay=0; lay<MdcCalNLayer; lay++){
162 if(fgHitLay[lay]) nhitlay++;
163 }
164 if(nhitlay < m_param.nHitLayCut) continue;
165
166 for(k=0; k<nhit; k++){
167 rechit = rectrk -> getRecHit(k);
168 lay = rechit -> getLayid();
169 doca = rechit -> getDocaInc();
170 resi = rechit -> getResiInc();
171 iLR = rechit -> getLR();
172 entrance = rechit -> getEntra();
173 tdr = rechit -> getTdrift();
174
175 if( (fabs(doca) > m_docaMax[lay]) ||
176 (fabs(resi) > m_param.resiCut[lay]) ){
177 continue;
178 }
179
180 if(0 == lay){
181 if( ! fgHitLay[1] ) continue;
182 } else if(42 == lay){
183 if( ! fgHitLay[41] ) continue;
184 } else{
185 if( (!fgHitLay[lay-1]) && (!fgHitLay[lay+1]) ) continue;
186 }
187
188 iEntr = m_mdcFunSvc -> getXtEntrIndex(entrance);
189
190 if(iLR < 2){
191 if(m_nhit[lay][iEntr][iLR] < m_maxNhit){
192 m_grxt[lay][iEntr][iLR] -> SetPoint(m_nhit[lay][iEntr][iLR],
193 tdr, fabs(doca));
194 m_nhit[lay][iEntr][iLR]++;
195 }
196 }
197
198 if(m_nhit[lay][iEntr][2] < m_maxNhit){
199 m_grxt[lay][iEntr][2] -> SetPoint(m_nhit[lay][iEntr][2],
200 tdr, fabs(doca));
201 m_nhit[lay][iEntr][2]++;
202 }
203 } // hit loop
204 } // track loop
205 return 1;
206}
207
209 IMessageSvc* msgSvc;
210 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
211 MsgStream log(msgSvc, "GrXtMdcCalib");
212 log << MSG::INFO << "GrXtMdcCalib::updateConst()" << endreq;
213
214 MdcCalib::updateConst(calconst);
215
216 int ord;
217 double xtpar[MdcCalNLayer][MdcCalNENTRXT][MdcCalLR][8];
218 TF1* fxtDr = new TF1("fxtDr", xtfun, 0, 300, 6);
219 TF1* fxtEd = new TF1("fxtEd", xtedge, 150, 500, 1);
220 if(1 == m_param.fixXtC0) fxtDr -> FixParameter(0, 0);
221
222 for(int lay=0; lay<MdcCalNLayer; lay++){
223 for(int iEntr=0; iEntr<MdcCalNENTRXT; iEntr++){
224 for(int lr=0; lr<MdcCalLR; lr++){
225 m_fgFit[lay][iEntr][lr] = false;
226 if(0 == m_param.fgCalib[lay]) continue;
227
228 if(m_nhit[lay][iEntr][lr] > 1000){
229 TMAX = calconst -> getXtpar(lay, iEntr, lr, 6);
230
231 m_grxt[lay][iEntr][lr] -> Fit("fxtDr", "Q+", "", 0, TMAX);
232
233 for(ord=0; ord<6; ord++){
234 xtpar[lay][iEntr][lr][ord] = fxtDr->GetParameter(ord);
235 }
236 xtpar[lay][iEntr][lr][6] = TMAX;
237
238 DMAX = 0.0;
239 for(ord=0; ord<6; ord++) DMAX += xtpar[lay][iEntr][lr][ord] * pow(TMAX, ord);
240
241 m_grxt[lay][iEntr][lr] -> Fit("fxtEd", "Q+", "", TMAX, TMAX+300);
242 xtpar[lay][iEntr][lr][7] = fxtEd->GetParameter(0);
243 if(xtpar[lay][iEntr][lr][7] < 0.0) xtpar[lay][iEntr][lr][7] = 0.0;
244 m_fgFit[lay][iEntr][lr] = true;
245
246// for(ord=0; ord<8; ord++){
247// calconst -> resetXtpar(lay, iEntr, lr, ord, xtpar[ord]);
248// }
249 }
250
251 } // end of lr loop
252 } // end of entrance angle loop
253 } // end of layer loop
254
255 ofstream fxtlog("xtlog");
256 for(int lay=0; lay<MdcCalNLayer; lay++){
257 for(int iEntr=0; iEntr<MdcCalNENTRXT; iEntr++){
258 for(int lr=0; lr<MdcCalLR; lr++){
259 fxtlog << setw(3) << lay << setw(3) << iEntr << setw(3) << lr;
260
261 int fgUpdate = -1;
262 if(m_fgFit[lay][iEntr][lr]){
263 fgUpdate = 1;
264 for(ord=0; ord<8; ord++) calconst->resetXtpar(lay, iEntr, lr, ord, xtpar[lay][iEntr][lr][ord]);
265 } else{
266 int iEntrNew = findXtEntr(lay, iEntr, lr);
267 if(-1 != iEntrNew){
268 fgUpdate = 2;
269 for(ord=0; ord<8; ord++){
270 calconst->resetXtpar(lay, iEntr, lr, ord, xtpar[lay][iEntrNew][lr][ord]);
271 }
272 }
273 }
274 fxtlog << setw(3) << fgUpdate;
275 for(ord=0; ord<8; ord++){
276 double par = calconst -> getXtpar(lay, iEntr, lr, ord);
277 fxtlog << setw(14) << par;
278 }
279 fxtlog << endl;
280 }
281 }
282 }
283 fxtlog.close();
284
285 cout << "Xt update finished. File xtlog was written." << endl;
286 delete fxtDr;
287 delete fxtEd;
288}
289
290Double_t GrXtMdcCalib::xtfun(Double_t *x, Double_t *par){
291 Double_t val = 0.0;
292 for(Int_t ord=0; ord<6; ord++){
293 val += par[ord] * pow(x[0], ord);
294 }
295 return val;
296}
297
298Double_t GrXtMdcCalib::xtedge(Double_t *x, Double_t *par){
299 double val = DMAX + (x[0] - TMAX) * par[0];
300 return val;
301}
302
303int GrXtMdcCalib::findXtEntr(int lay, int iEntr, int lr) const {
304 int id0 = 8;
305 int id1 = 9;
306 int idmax = 17;
307 int entrId = -1;
308 if(iEntr <= id0){
309 int id = -1;
310 for(int i=iEntr; i<=id0; i++){
311 if(m_fgFit[lay][i][lr]){
312 id = i;
313 break;
314 }
315 }
316 if(-1 != id) entrId = id;
317 else{
318 for(int i=iEntr; i>=0; i--){
319 if(m_fgFit[lay][i][lr]){
320 id = i;
321 break;
322 }
323 }
324 entrId = id;
325 }
326 } else{
327 int id = -1;
328 for(int i=iEntr; i>=id1; i--){
329 if(m_fgFit[lay][i][lr]){
330 id = i;
331 break;
332 }
333 }
334 if(-1 != id) entrId = id;
335 else{
336 for(int i=iEntr; i<idmax; i++){
337 if(m_fgFit[lay][i][lr]){
338 id = i;
339 break;
340 }
341 }
342 entrId = id;
343 }
344 }
345 if(-1 == entrId){
346 cout << "find EntrId error " << "layer " << lay << " iEntr " << iEntr << " lr " << lr << endl;
347 }
348
349 return entrId;
350}
void Fit()
Definition: Eangle1D/Fit.cxx:3
const int MdcCalNLayer
Definition: MdcCalParams.h:6
const int MdcCalNENTRXT
Definition: MdcCalParams.h:12
const int MdcCalLR
Definition: MdcCalParams.h:10
IMessageSvc * msgSvc()
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)
int findXtEntr(int lay, int iEntr, int lr) const
static Double_t xtedge(Double_t *x, Double_t *par)
static Double_t xtfun(Double_t *x, Double_t *par)
int fillHist(MdcCalEvent *event)
int updateConst(MdcCalibConst *calconst)
double maxDocaOuter
Definition: MdcCalParams.h:73
int fgCalib[MdcCalNLayer]
Definition: MdcCalParams.h:75
double maxDocaInner
Definition: MdcCalParams.h:72
double dzCut
Definition: MdcCalParams.h:71
double drCut
Definition: MdcCalParams.h:70
double resiCut[MdcCalNLayer]
Definition: MdcCalParams.h:79
double getDz() const
Definition: MdcCalRecTrk.h:33
double getDr() const
Definition: MdcCalRecTrk.h:30
void resetXtpar(int lay, int entr, int lr, int order, double val)
virtual void clear()=0
Definition: MdcCalib.cxx:76
virtual void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)=0
Definition: MdcCalib.cxx:202
virtual int updateConst(MdcCalibConst *calconst)=0
Definition: MdcCalib.cxx:1322
virtual int fillHist(MdcCalEvent *event)=0
Definition: MdcCalib.cxx:692
double x[1000]
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)