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"
19double GrXtMdcCalib::DMAX;
20double GrXtMdcCalib::TMAX;
31 cout <<
"~GrXtMdcCalib" << endl;
35 delete m_grxt[lay][iEntr][iLR];
48 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
49 MsgStream log(
msgSvc,
"GrXtMdcCalib");
50 log << MSG::INFO <<
"GrXtMdcCalib::initialize()" << endreq;
53 m_mdcGeomSvc = mdcGeomSvc;
54 m_mdcFunSvc = mdcFunSvc;
55 m_mdcUtilitySvc = mdcUtilitySvc;
64 m_fdXt =
new TFolder(
"fdXtGr",
"fdXtGr");
65 m_hlist ->
Add(m_fdXt);
67 m_haxis =
new TH2F(
"axis",
"", 50, 0, 300, 50, 0, 9);
68 m_haxis -> SetStats(0);
69 m_fdXt ->
Add(m_haxis);
74 m_nhit[lay][iEntr][iLR] = 0;
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);
81 m_fdXt ->
Add(m_grxt[lay][iEntr][iLR]);
89 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
90 MsgStream log(
msgSvc,
"GrXtMdcCalib");
91 log << MSG::DEBUG <<
"GrXtMdcCalib::fillHist()" << endreq;
96 bool esCutFg =
event->getEsCutFlag();
97 if( ! esCutFg )
return -1;
128 int ntrk =
event -> getNTrk();
129 for(i=0; i<ntrk; i++){
131 rectrk =
event->getRecTrk(i);
132 nhit = rectrk -> getNHits();
135 dr = rectrk->
getDr();
136 if(fabs(dr) > m_param.
drCut)
continue;
139 dz = rectrk->
getDz();
140 if(fabs(dz) > m_param.
dzCut)
continue;
143 fgHitLay[lay] =
false;
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;
158 if(! fgTrk)
continue;
162 if(fgHitLay[lay]) nhitlay++;
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();
175 if( (fabs(doca) > m_docaMax[lay]) ||
176 (fabs(resi) > m_param.
resiCut[lay]) ){
181 if( ! fgHitLay[1] )
continue;
182 }
else if(42 == lay){
183 if( ! fgHitLay[41] )
continue;
185 if( (!fgHitLay[lay-1]) && (!fgHitLay[lay+1]) )
continue;
188 iEntr = m_mdcFunSvc -> getXtEntrIndex(entrance);
191 if(m_nhit[lay][iEntr][iLR] < m_maxNhit){
192 m_grxt[lay][iEntr][iLR] -> SetPoint(m_nhit[lay][iEntr][iLR],
194 m_nhit[lay][iEntr][iLR]++;
198 if(m_nhit[lay][iEntr][2] < m_maxNhit){
199 m_grxt[lay][iEntr][2] -> SetPoint(m_nhit[lay][iEntr][2],
201 m_nhit[lay][iEntr][2]++;
210 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
211 MsgStream log(
msgSvc,
"GrXtMdcCalib");
212 log << MSG::INFO <<
"GrXtMdcCalib::updateConst()" << endreq;
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);
225 m_fgFit[lay][iEntr][lr] =
false;
226 if(0 == m_param.
fgCalib[lay])
continue;
228 if(m_nhit[lay][iEntr][lr] > 1000){
229 TMAX = calconst -> getXtpar(lay, iEntr, lr, 6);
231 m_grxt[lay][iEntr][lr] ->
Fit(
"fxtDr",
"Q+",
"", 0, TMAX);
233 for(ord=0; ord<6; ord++){
234 xtpar[lay][iEntr][lr][ord] = fxtDr->GetParameter(ord);
236 xtpar[lay][iEntr][lr][6] = TMAX;
239 for(ord=0; ord<6; ord++) DMAX += xtpar[lay][iEntr][lr][ord] * pow(TMAX, ord);
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;
255 ofstream fxtlog(
"xtlog");
259 fxtlog << setw(3) << lay << setw(3) << iEntr << setw(3) << lr;
262 if(m_fgFit[lay][iEntr][lr]){
264 for(ord=0; ord<8; ord++) calconst->
resetXtpar(lay, iEntr, lr, ord, xtpar[lay][iEntr][lr][ord]);
269 for(ord=0; ord<8; ord++){
270 calconst->
resetXtpar(lay, iEntr, lr, ord, xtpar[lay][iEntrNew][lr][ord]);
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;
285 cout <<
"Xt update finished. File xtlog was written." << endl;
292 for(Int_t ord=0; ord<6; ord++){
293 val += par[ord] * pow(
x[0], ord);
299 double val = DMAX + (
x[0] - TMAX) * par[0];
310 for(
int i=iEntr; i<=id0; i++){
311 if(m_fgFit[lay][i][lr]){
316 if(-1 !=
id) entrId = id;
318 for(
int i=iEntr; i>=0; i--){
319 if(m_fgFit[lay][i][lr]){
328 for(
int i=iEntr; i>=id1; i--){
329 if(m_fgFit[lay][i][lr]){
334 if(-1 !=
id) entrId = id;
336 for(
int i=iEntr; i<idmax; i++){
337 if(m_fgFit[lay][i][lr]){
346 cout <<
"find EntrId error " <<
"layer " << lay <<
" iEntr " << iEntr <<
" lr " << lr << endl;
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)
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)
int fgCalib[MdcCalNLayer]
double resiCut[MdcCalNLayer]
void resetXtpar(int lay, int entr, int lr, int order, double val)
virtual void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)=0
virtual int updateConst(MdcCalibConst *calconst)=0
virtual int fillHist(MdcCalEvent *event)=0