5#include "GaudiKernel/IMessageSvc.h"
6#include "GaudiKernel/StatusCode.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/Bootstrap.h"
19#ifndef ENABLE_BACKWARDS_COMPATIBILITY
32 m_docaCut[lay][0] = 0.5;
33 m_docaCut[lay][1] = 5.5;
35 m_docaCut[lay][0] = 0.5;
36 m_docaCut[lay][1] = 7.5;
49 for(
int lay=0; lay<
LAYERNMAX; lay++)
delete m_hresLay[lay];
51 for(
int lay=0; lay<
LAYERNMAX; lay++)
delete m_hresLayRec[lay];
59 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
60 MsgStream log(
msgSvc,
"MilleAlign");
61 log << MSG::INFO <<
"MilleAlign::initialize()" << endreq;
65 StatusCode sc = Gaudi::svcLocator() -> service (
"MdcUtilitySvc",imdcUtilitySvc);
66 m_mdcUtilitySvc=
dynamic_cast<MdcUtilitySvc*
> (imdcUtilitySvc);
67 if ( sc.isFailure() ){
68 log << MSG::FATAL <<
"Could not load MdcUtilitySvc!" << endreq;
72 m_mdcGeomSvc = mdcGeomSvc;
73 m_mdcFunSvc = mdcFunSvc;
76 m_hresAll =
new TH1F(
"HResAllInc",
"", 200, -1.0, 1.0);
77 m_hlist->Add(m_hresAll);
79 m_hresInn =
new TH1F(
"HResInnInc",
"", 200, -1.0, 1.0);
80 m_hlist->Add(m_hresInn);
82 m_hresStp =
new TH1F(
"HResStpInc",
"", 200, -1.0, 1.0);
83 m_hlist->Add(m_hresStp);
85 m_hresOut =
new TH1F(
"HResOutInc",
"", 200, -1.0, 1.0);
86 m_hlist->Add(m_hresOut);
90 sprintf(hname,
"Res_Layer%02d", lay);
91 m_hresLay[lay] =
new TH1F(hname,
"", 200, -1.0, 1.0);
92 m_hlist->Add(m_hresLay[lay]);
95 m_hresAllRec =
new TH1F(
"HResAllRecInc",
"", 200, -1.0, 1.0);
96 m_hlist->Add(m_hresAllRec);
98 sprintf(hname,
"Res_LayerRec%02d", lay);
99 m_hresLayRec[lay] =
new TH1F(hname,
"", 200, -1.0, 1.0);
100 m_hlist->Add(m_hresLayRec[lay]);
104 m_hddoca =
new TH1F(
"delt_doca",
"", 200, -1.0, 1.0);
105 m_hlist->Add(m_hddoca);
108 sprintf(hname,
"delt_docaLay%02d", lay);
109 m_hddocaLay[lay] =
new TH1F(hname,
"", 200, -1.0, 1.0);
110 m_hlist->Add(m_hddocaLay[lay]);
126 m_pMilleAlign -> InitMille(&m_dofs[0], &m_sigm[0], m_nglo, m_nloc,
129 m_derGB.resize(m_npar);
130 m_derNonLin.resize(m_npar);
131 m_par.resize(m_npar);
132 m_error.resize(m_npar);
133 m_pull.resize(m_npar);
135 m_derLC.resize(m_nloc);
138 std::vector<double> constTX;
139 std::vector<double> constTY;
140 std::vector<double> constRZ;
142 std::vector<double> constTXE;
143 std::vector<double> constTXW;
144 std::vector<double> constTYE;
145 std::vector<double> constTYW;
146 std::vector<double> constRZE;
147 std::vector<double> constRZW;
149 constTX.resize(m_npar);
150 constTY.resize(m_npar);
151 constRZ.resize(m_npar);
153 constTXE.resize(m_npar);
154 constTXW.resize(m_npar);
155 constTYE.resize(m_npar);
156 constTYW.resize(m_npar);
157 constRZE.resize(m_npar);
158 constRZW.resize(m_npar);
160 for(i=0; i<m_npar; i++){
190 m_pMilleAlign -> ConstF(&constTXE[0], 0.0);
191 m_pMilleAlign -> ConstF(&constTXW[0], 0.0);
192 m_pMilleAlign -> ConstF(&constTYE[0], 0.0);
193 m_pMilleAlign -> ConstF(&constTYW[0], 0.0);
194 m_pMilleAlign -> ConstF(&constRZE[0], 0.0);
195 m_pMilleAlign -> ConstF(&constRZW[0], 0.0);
200 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
201 MsgStream log(
msgSvc,
"MilleAlign");
202 log << MSG::DEBUG <<
"MilleAlign::fillTree()" << endreq;
232 int ntrk =
event -> getNTrk();
233 if( (ntrk<m_param.
nTrkCut[0]) || (ntrk>m_param.
nTrkCut[1]))
return false;
235 for(itrk=0; itrk<ntrk; itrk++){
236 rectrk =
event->getRecTrk(itrk);
239 trkpar[0] = rectrk -> getDr();
240 trkpar[1] = rectrk -> getPhi0();
241 trkpar[2] = rectrk -> getKappa();
242 trkpar[3] = rectrk -> getDz();
243 trkpar[4] = rectrk -> getTanLamda();
245 int nHit = rectrk -> getNHits();
246 if(nHit < m_param.
nHitCut)
continue;
247 if(fabs(trkpar[0]) > m_param.
drCut)
continue;
248 if(fabs(trkpar[3]) > m_param.
dzCut)
continue;
250 HepVector rechelix = rectrk->
getHelix();
251 HepVector helix = rectrk->
getHelix();
255 for(ihit=0; ihit<nHit; ihit++){
256 rechit = rectrk -> getRecHit(ihit);
257 lr = rechit->
getLR();
258 lay = rechit -> getLayid();
259 cel = rechit -> getCellid();
260 pWire = m_mdcGeomSvc -> Wire(lay, cel);
261 dmeas = rechit -> getDmeas();
262 zhit = rechit -> getZhit();
263 hitSigm = rechit -> getErrDmeas();
265 wpos[0] = pWire -> Backward().x();
266 wpos[1] = pWire -> Backward().y();
267 wpos[2] = pWire -> Backward().z();
268 wpos[3] = pWire -> Forward().x();
269 wpos[4] = pWire -> Forward().y();
270 wpos[5] = pWire -> Forward().z();
271 wpos[6] = pWire -> Tension();
274 double doca = (m_mdcUtilitySvc->
doca(lay, cel, helix, helixErr))*10.0;
276 resi = -1.0*dmeas - doca;
277 if ((fabs(doca) < m_docaCut[lay][0]) || (fabs(doca) > m_docaCut[lay][1]) ||
278 (fabs(resi) > m_resiCut[lay]))
continue;
281 resiRec = rechit -> getResiIncLR();
283 double dd = fabs(doca) - fabs(rechit->
getDocaInc());
284 m_hddoca -> Fill(dd);
285 m_hddocaLay[lay] -> Fill(dd);
288 m_hresAll->Fill(resi);
289 if(lay < 8) m_hresInn->Fill(resi);
290 else if(lay < 20) m_hresStp->Fill(resi);
291 else m_hresOut->Fill(resi);
292 m_hresLay[lay]->Fill(resi);
294 m_hresAllRec->Fill(resiRec);
295 m_hresLayRec[lay]->Fill(resiRec);
298 m_pMilleAlign -> ZerLoc(&m_derGB[0], &m_derLC[0], &m_derNonLin[0]);
301 for(ipar=0; ipar<m_nloc; ipar++){
302 if( ! getDeriLoc(ipar, lay, cel ,rechelix, helixErr, deri) ){
303 cout <<
"getDeriLoc == false!" << setw(12) << itrk << setw(12) << ipar << endl;
306 m_derLC[ipar] = deri;
311 for(ipar=0; ipar<m_nGloHit; ipar++){
312 iparGB = getAlignParId(lay, ipar);
313 if( ! getDeriGlo(ipar, iparGB, lay, cel, helix, helixErr, wpos, deri) )
315 cout <<
"getDeriGlo == false!" << setw(12) << itrk << setw(12) << ipar << endl;
318 m_derGB[iparGB] = deri;
320 m_pMilleAlign -> EquLoc(&m_derGB[0], &m_derLC[0], &m_derNonLin[0], resi, hitSigm);
324 bool sc = m_pMilleAlign -> FitLoc(m_pMilleAlign->
GetTrackNumber(), trkparms, 0);
325 if(sc) m_pMilleAlign -> SetTrackNumber( m_pMilleAlign->
GetTrackNumber()+1 );
333 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
334 MsgStream log(
msgSvc,
"MilleAlign");
335 log << MSG::INFO <<
"MilleAlign::updateConst()" << endreq;
337 m_pMilleAlign -> MakeGlobalFit(&m_par[0], &m_error[0], &m_pull[0]);
344 for(iEP=0; iEP<
NEP; iEP++){
345 ipar = i *
NEP + iEP;
361 alignPar->
setDelRz(iEP, val/1000.0);
362 alignPar->
setErrRz(iEP, err/1000.0);
368int MilleAlign::getAlignParId(
int lay,
int iparHit){
371 else if(lay < 10) ip = 1;
372 else if(lay < 12) ip = 2;
373 else if(lay < 14) ip = 3;
374 else if(lay < 16) ip = 4;
375 else if(lay < 18) ip = 5;
376 else if(lay < 20) ip = 6;
380 int ipar = iparHit * 8 + ip;
384bool MilleAlign::getDeriLoc(
int ipar,
int lay,
int cel, HepVector rechelix, HepSymMatrix &helixErr,
double &deri){
391 for(i=0; i<m_nloc; i++) sampar[i] = rechelix[i];
392 double startpar = rechelix[ipar] - 0.5*
gStepLC[ipar]*(double)
gNsamLC;
395 sampar[ipar] = startpar + (double)i *
gStepLC[ipar];
396 xxLC[i] = sampar[ipar];
397 if(0==ipar || 3==ipar) xxLC[i] *= 10.;
399 HepVector helix = sampar;
400 bool passCellRequired =
false;
401 doca = (m_mdcUtilitySvc->
doca(lay, cel, helix, helixErr,passCellRequired))*10.0;
410 if (0==ipar || 3==ipar) rechelix[ipar] *= 10.;
411 TSpline3* pSpline3 =
new TSpline3(
"deri", xxLC, yyLC,
gNsamLC);
412 deri = pSpline3->Derivative(rechelix[ipar]);
417bool MilleAlign::getDeriGlo(
int iparHit,
int iparGB,
int lay,
int cel, HepVector helix,
418 HepSymMatrix &helixErr,
double wpos[],
double &deri){
424 double dAlignParini = 0.0;
425 double startpar = dAlignParini - 0.5*
gStepGB[iparGB]*(double)
gNsamGB;
427 for(i=0; i<7; i++) wposSam[i] = wpos[i];
430 dAlignPar = startpar + (double)i *
gStepGB[iparGB];
433 wposSam[0] = wpos[0] + dAlignPar;
434 }
else if(1 == iparHit){
435 wposSam[3] = wpos[3] + dAlignPar;
436 }
else if(2 == iparHit){
437 wposSam[1] = wpos[1] + dAlignPar;
438 }
else if(3 == iparHit){
439 wposSam[4] = wpos[4] + dAlignPar;
440 }
else if(4 == iparHit){
441 wposSam[0] = wpos[0] - (wpos[1] * dAlignPar * 0.001);
442 wposSam[1] = wpos[1] + (wpos[0] * dAlignPar * 0.001);
443 }
else if(5 == iparHit){
444 wposSam[3] = wpos[3] - (wpos[4] * dAlignPar * 0.001);
445 wposSam[4] = wpos[4] + (wpos[3] * dAlignPar * 0.001);
448 HepPoint3D eastP(wposSam[0]/10., wposSam[1]/10., wposSam[2]/10.);
449 HepPoint3D westP(wposSam[3]/10., wposSam[4]/10., wposSam[5]/10.);
450 doca = (m_mdcUtilitySvc->
doca(lay, cel, eastP, westP, helix, helixErr))*10.0;
452 if(NULL == doca)
return false;
457 TSpline3* pSpline3 =
new TSpline3(
"deri", xxGB, yyGB,
gNsamGB);
458 deri = pSpline3 -> Derivative(dAlignParini);
HepGeom::Point3D< double > HepPoint3D
double getDocaInc() const
HepSymMatrix getHelixErr() const
HepVector getHelix() const
void setErrRz(int iEP, double val)
void setDelDy(int iEP, double val)
void setDelRz(int iEP, double val)
void setErrDx(int iEP, double val)
void setDelDx(int iEP, double val)
void setErrDy(int iEP, double val)
double doca(int layer, int cell, const HepVector helix, const HepSymMatrix errMat, bool passCellRequired=true, bool doSag=true) const
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc)
bool fillHist(MdcAliEvent *event)
void updateConst(MdcAlignPar *alignPar)
const double g_res_cut_init
const double g_start_chi_cut