5#include "GaudiKernel/Bootstrap.h"
6#include "GaudiKernel/IMessageSvc.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/StatusCode.h"
10#include "Identifier/MdcID.h"
19#ifndef ENABLE_BACKWARDS_COMPATIBILITY
29 for (
int lay = 0; lay <
LAYERNMAX; lay++ )
34 m_docaCut[lay][0] = 0.5;
35 m_docaCut[lay][1] = 5.5;
39 m_docaCut[lay][0] = 0.5;
40 m_docaCut[lay][1] = 7.5;
52 for (
int lay = 0; lay <
LAYERNMAX; lay++ )
delete m_hresLay[lay];
54 for (
int lay = 0; lay <
LAYERNMAX; lay++ )
delete m_hresLayRec[lay];
62 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc );
63 MsgStream log(
msgSvc,
"MilleAlign" );
64 log << MSG::INFO <<
"MilleAlign::initialize()" << endmsg;
67 m_mdcGeomSvc = mdcGeomSvc;
68 m_mdcFunSvc = mdcFunSvc;
69 m_mdcUtilitySvc = mdcUtilitySvc;
72 m_hresAll =
new TH1F(
"HResAllInc",
"", 200, -1.0, 1.0 );
73 m_hlist->Add( m_hresAll );
75 m_hresInn =
new TH1F(
"HResInnInc",
"", 200, -1.0, 1.0 );
76 m_hlist->Add( m_hresInn );
78 m_hresStp =
new TH1F(
"HResStpInc",
"", 200, -1.0, 1.0 );
79 m_hlist->Add( m_hresStp );
81 m_hresOut =
new TH1F(
"HResOutInc",
"", 200, -1.0, 1.0 );
82 m_hlist->Add( m_hresOut );
85 for (
int lay = 0; lay <
LAYERNMAX; lay++ )
87 sprintf( hname,
"Res_Layer%02d", lay );
88 m_hresLay[lay] =
new TH1F( hname,
"", 200, -1.0, 1.0 );
89 m_hlist->Add( m_hresLay[lay] );
92 m_hresAllRec =
new TH1F(
"HResAllRecInc",
"", 200, -1.0, 1.0 );
93 m_hlist->Add( m_hresAllRec );
94 for (
int lay = 0; lay <
LAYERNMAX; lay++ )
96 sprintf( hname,
"Res_LayerRec%02d", lay );
97 m_hresLayRec[lay] =
new TH1F( hname,
"", 200, -1.0, 1.0 );
98 m_hlist->Add( m_hresLayRec[lay] );
102 m_hddoca =
new TH1F(
"delt_doca",
"", 200, -1.0, 1.0 );
103 m_hlist->Add( m_hddoca );
105 for (
int lay = 0; lay <
LAYERNMAX; lay++ )
107 sprintf( hname,
"delt_docaLay%02d", lay );
108 m_hddocaLay[lay] =
new TH1F( hname,
"", 200, -1.0, 1.0 );
109 m_hlist->Add( m_hddocaLay[lay] );
126 m_pMilleAlign->InitMille( &m_dofs[0], &m_sigm[0], m_nglo, m_nloc,
g_start_chi_cut, 3,
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++ )
191 m_pMilleAlign->ConstF( &constTXE[0], 0.0 );
192 m_pMilleAlign->ConstF( &constTXW[0], 0.0 );
193 m_pMilleAlign->ConstF( &constTYE[0], 0.0 );
194 m_pMilleAlign->ConstF( &constTYW[0], 0.0 );
195 m_pMilleAlign->ConstF( &constRZE[0], 0.0 );
196 m_pMilleAlign->ConstF( &constRZW[0], 0.0 );
201 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc );
202 MsgStream log(
msgSvc,
"MilleAlign" );
203 log << MSG::DEBUG <<
"MilleAlign::fillTree()" << endmsg;
233 int ntrk =
event->getNTrk();
234 if ( ( ntrk < m_param.nTrkCut[0] ) || ( ntrk > m_param.nTrkCut[1] ) )
return false;
236 for ( itrk = 0; itrk < ntrk; itrk++ )
238 rectrk =
event->getRecTrk( itrk );
241 trkpar[0] = rectrk->
getDr();
244 trkpar[3] = rectrk->
getDz();
248 if ( nHit < m_param.nHitCut )
continue;
249 if ( fabs( trkpar[0] ) > m_param.drCut )
continue;
250 if ( fabs( trkpar[3] ) > m_param.dzCut )
continue;
252 HepVector rechelix = rectrk->
getHelix();
253 HepVector helix = rectrk->
getHelix();
257 for ( ihit = 0; ihit < nHit; ihit++ )
260 lr = rechit->
getLR();
263 pWire = m_mdcGeomSvc->Wire( lay, cel );
271 wpos[3] = pWire->
Forward().x();
272 wpos[4] = pWire->
Forward().y();
273 wpos[5] = pWire->
Forward().z();
277 double doca = ( m_mdcUtilitySvc->doca( lay, cel, helix, helixErr ) ) * 10.0;
279 resi = -1.0 * dmeas - doca;
280 if ( ( fabs( doca ) < m_docaCut[lay][0] ) || ( fabs( doca ) > m_docaCut[lay][1] ) ||
281 ( fabs( resi ) > m_resiCut[lay] ) )
287 double dd = fabs( doca ) - fabs( rechit->
getDocaInc() );
288 m_hddoca->Fill( dd );
289 m_hddocaLay[lay]->Fill( dd );
292 m_hresAll->Fill( resi );
293 if ( lay < 8 ) m_hresInn->Fill( resi );
294 else if ( lay < 20 ) m_hresStp->Fill( resi );
295 else m_hresOut->Fill( resi );
296 m_hresLay[lay]->Fill( resi );
298 m_hresAllRec->Fill( resiRec );
299 m_hresLayRec[lay]->Fill( resiRec );
302 m_pMilleAlign->ZerLoc( &m_derGB[0], &m_derLC[0], &m_derNonLin[0] );
305 for ( ipar = 0; ipar < m_nloc; ipar++ )
307 if ( !getDeriLoc( ipar, lay, cel, rechelix, helixErr, deri ) )
309 cout <<
"getDeriLoc == false!" << setw( 12 ) << itrk << setw( 12 ) << ipar << endl;
312 m_derLC[ipar] = deri;
316 for ( ipar = 0; ipar < m_nGloHit; ipar++ )
318 iparGB = getAlignParId( lay, ipar );
319 if ( !getDeriGlo( ipar, iparGB, lay, cel, helix, helixErr, wpos, deri ) )
321 cout <<
"getDeriGlo == false!" << setw( 12 ) << itrk << setw( 12 ) << ipar << endl;
324 m_derGB[iparGB] = deri;
326 m_pMilleAlign->EquLoc( &m_derGB[0], &m_derLC[0], &m_derNonLin[0], resi, hitSigm );
330 bool sc = m_pMilleAlign->FitLoc( m_pMilleAlign->GetTrackNumber(), trkparms, 0 );
331 if ( sc ) m_pMilleAlign->SetTrackNumber( m_pMilleAlign->GetTrackNumber() + 1 );
338 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc );
339 MsgStream log(
msgSvc,
"MilleAlign" );
340 log << MSG::INFO <<
"MilleAlign::updateConst()" << endmsg;
342 m_pMilleAlign->MakeGlobalFit( &m_par[0], &m_error[0], &m_pull[0] );
350 for ( iEP = 0; iEP <
NEP; iEP++ )
352 ipar = i *
NEP + iEP;
376 alignPar->
setDelRz( iEP, val / 1000.0 );
377 alignPar->
setErrRz( iEP, err / 1000.0 );
383int MilleAlign::getAlignParId(
int lay,
int iparHit ) {
385 if ( lay < 8 ) ip = 0;
386 else if ( lay < 10 ) ip = 1;
387 else if ( lay < 12 ) ip = 2;
388 else if ( lay < 14 ) ip = 3;
389 else if ( lay < 16 ) ip = 4;
390 else if ( lay < 18 ) ip = 5;
391 else if ( lay < 20 ) ip = 6;
395 int ipar = iparHit * 8 + ip;
399bool MilleAlign::getDeriLoc(
int ipar,
int lay,
int cel, HepVector rechelix,
400 HepSymMatrix& helixErr,
double& deri ) {
403 HepVector sampar(
NTRKPAR, 0 );
407 for ( i = 0; i < m_nloc; i++ ) sampar[i] = rechelix[i];
408 double startpar = rechelix[ipar] - 0.5 *
gStepLC[ipar] * (double)
gNsamLC;
410 for ( i = 0; i <
gNsamLC; i++ )
412 sampar[ipar] = startpar + (double)i *
gStepLC[ipar];
413 xxLC[i] = sampar[ipar];
414 if ( 0 == ipar || 3 == ipar ) xxLC[i] *= 10.;
416 HepVector helix = sampar;
417 bool passCellRequired =
false;
418 doca = ( m_mdcUtilitySvc->doca( lay, cel, helix, helixErr, passCellRequired ) ) * 10.0;
429 if ( 0 == ipar || 3 == ipar ) rechelix[ipar] *= 10.;
430 TSpline3* pSpline3 =
new TSpline3(
"deri", xxLC, yyLC,
gNsamLC );
431 deri = pSpline3->Derivative( rechelix[ipar] );
436bool MilleAlign::getDeriGlo(
int iparHit,
int iparGB,
int lay,
int cel, HepVector helix,
437 HepSymMatrix& helixErr,
double wpos[],
double& deri ) {
443 double dAlignParini = 0.0;
444 double startpar = dAlignParini - 0.5 *
gStepGB[iparGB] * (double)
gNsamGB;
446 for ( i = 0; i < 7; i++ ) wposSam[i] = wpos[i];
448 for ( i = 0; i <
gNsamGB; i++ )
450 dAlignPar = startpar + (double)i *
gStepGB[iparGB];
454 wposSam[0] = wpos[0] + dAlignPar;
456 else if ( 1 == iparHit )
458 wposSam[3] = wpos[3] + dAlignPar;
460 else if ( 2 == iparHit )
462 wposSam[1] = wpos[1] + dAlignPar;
464 else if ( 3 == iparHit )
466 wposSam[4] = wpos[4] + dAlignPar;
468 else if ( 4 == iparHit )
470 wposSam[0] = wpos[0] - ( wpos[1] * dAlignPar * 0.001 );
471 wposSam[1] = wpos[1] + ( wpos[0] * dAlignPar * 0.001 );
473 else if ( 5 == iparHit )
475 wposSam[3] = wpos[3] - ( wpos[4] * dAlignPar * 0.001 );
476 wposSam[4] = wpos[4] + ( wpos[3] * dAlignPar * 0.001 );
480 HepPoint3D eastP( wposSam[0] / 10., wposSam[1] / 10., wposSam[2] / 10. );
481 HepPoint3D westP( wposSam[3] / 10., wposSam[4] / 10., wposSam[5] / 10. );
483 ( m_mdcUtilitySvc->doca( lay, cel, eastP, westP, helix, helixErr ) ) * 10.0;
487 if ( doca == 0 )
return false;
491 TSpline3* pSpline3 =
new TSpline3(
"deri", xxGB, yyGB,
gNsamGB );
492 deri = pSpline3->Derivative( dAlignParini );
HepGeom::Point3D< double > HepPoint3D
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)
double getErrDmeas() const
double getResiIncLR() const
double getDocaInc() const
MdcAliRecHit * getRecHit(int index) const
HepSymMatrix getHelixErr() const
HepVector getHelix() const
double getTanLamda() 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)
HepPoint3D Forward(void) const
HepPoint3D Backward(void) const
double Tension(void) const
bool fillHist(MdcAliEvent *event)
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)
void updateConst(MdcAlignPar *alignPar)
const double g_res_cut_init
const double g_start_chi_cut