89 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc );
90 MsgStream log(
msgSvc,
"ResiAlign" );
91 log << MSG::INFO <<
"ResiAlign::initialize()" << endmsg;
94 m_mdcGeomSvc = mdcGeomSvc;
95 m_mdcFunSvc = mdcFunSvc;
96 m_mdcUtilitySvc = mdcUtilitySvc;
99 for (
int lay = 0; lay < 43; lay++ )
101 zeast = m_mdcGeomSvc->Wire( lay, 0 )->Backward().z();
102 m_zrange[lay][1] = 2.0 * fabs( zeast ) / (double)m_ndiv;
103 m_zrange[lay][0] = -1.0 * m_zrange[lay][1];
105 m_radii[lay] = m_mdcGeomSvc->Layer( lay )->Radius();
108 for (
int wir = 0; wir <
WIRENMAX; wir++ )
110 m_xe[wir] = m_mdcGeomSvc->Wire( wir )->Backward().x();
111 m_ye[wir] = m_mdcGeomSvc->Wire( wir )->Backward().y();
112 m_ze[wir] = m_mdcGeomSvc->Wire( wir )->Backward().z();
113 m_xw[wir] = m_mdcGeomSvc->Wire( wir )->Forward().x();
114 m_yw[wir] = m_mdcGeomSvc->Wire( wir )->Forward().y();
115 m_zw[wir] = m_mdcGeomSvc->Wire( wir )->Forward().z();
121 INTupleSvc* ntupleSvc;
122 Gaudi::svcLocator()->service(
"NTupleSvc", ntupleSvc );
123 for ( iEP = 0; iEP <=
NEP; iEP++ )
125 if ( iEP <
NEP )
sprintf( hname,
"FILE137/align%02d", iEP );
126 else sprintf( hname,
"FILE137/alignAll" );
128 NTuplePtr nt( ntupleSvc, hname );
129 if ( nt ) m_tuple[iEP] = nt;
132 m_tuple[iEP] = ntupleSvc->book( hname, CLID_ColumnWiseTuple,
"align" );
135 m_tuple[iEP]->addItem(
"run", m_iRun[iEP] );
136 m_tuple[iEP]->addItem(
"evt", m_iEvt[iEP] );
137 m_tuple[iEP]->addItem(
"resi", m_resi[iEP] );
138 m_tuple[iEP]->addItem(
"p", m_p[iEP] );
139 m_tuple[iEP]->addItem(
"pt", m_pt[iEP] );
140 m_tuple[iEP]->addItem(
"phi", m_phi[iEP] );
141 m_tuple[iEP]->addItem(
"lay", m_lay[iEP] );
142 m_tuple[iEP]->addItem(
"lr", m_lr[iEP] );
143 m_tuple[iEP]->addItem(
"cel", m_cel[iEP] );
145 else { log << MSG::FATAL <<
"Cannot book N-tuple:" << long( m_tuple[iEP] ) << endmsg; }
149 m_hnTrk =
new TH1F(
"HNtrack",
"", 10, -0.5, 9.5 );
150 m_hlist->Add( m_hnTrk );
152 m_hnHit =
new TH1F(
"HNhit",
"", 100, -0.5, 99.5 );
153 m_hlist->Add( m_hnHit );
155 m_hlayHitmap =
new TH1F(
"Hitmap",
"", 43, -0.5, 42.5 );
156 m_hlist->Add( m_hlayHitmap );
158 m_hresAll =
new TH1F(
"HResAllInc",
"", 200, -1.0, 1.0 );
159 m_hlist->Add( m_hresAll );
161 m_hresInn =
new TH1F(
"HResInnInc",
"", 200, -1.0, 1.0 );
162 m_hlist->Add( m_hresInn );
164 m_hresStp =
new TH1F(
"HResStpInc",
"", 200, -1.0, 1.0 );
165 m_hlist->Add( m_hresStp );
167 m_hresOut =
new TH1F(
"HResOutInc",
"", 200, -1.0, 1.0 );
168 m_hlist->Add( m_hresOut );
173 sprintf( hname,
"Res_Layer%02d", lay );
174 m_hresLay[lay] =
new TH1F( hname,
"", 200, -1.0, 1.0 );
175 m_hlist->Add( m_hresLay[lay] );
177 for (
int i = 0; i < 4; i++ )
179 if ( 0 == i )
sprintf( hname,
"Resi_Lay%02d_Up_L", lay );
180 else if ( 1 == i )
sprintf( hname,
"Resi_Lay%02d_Up_R", lay );
181 else if ( 2 == i )
sprintf( hname,
"Resi_Lay%02d_Dw_L", lay );
182 else sprintf( hname,
"Resi_Lay%02d_Dw_R", lay );
183 m_hresLay_LR[lay][i] =
new TH1F( hname,
"", 200, -1.0, 1.0 );
184 m_hlist->Add( m_hresLay_LR[lay][i] );
188 for ( iEP = 0; iEP <
NEP; iEP++ )
190 m_gr[iEP] =
new TGraph();
191 sprintf( hname,
"grResi%02d", iEP );
192 m_gr[iEP]->SetName( hname );
193 m_hlist->Add( m_gr[iEP] );
195 m_fevt.open(
"evt.txt" );
200 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc );
201 MsgStream log(
msgSvc,
"ResiAlign" );
202 log << MSG::DEBUG <<
"ResiAlign::fillHist()" << endmsg;
204 bool esCutFg =
event->getEsCutFlag();
247 IDataProviderSvc* eventSvc = NULL;
248 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc );
249 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc,
"/Event/EventHeader" );
252 log << MSG::FATAL <<
"Could not find Event Header" << endmsg;
254 return ( StatusCode::FAILURE );
256 int iEvt = eventHeader->eventNumber();
257 int iRun = eventHeader->runNumber();
259 int nTrk =
event->getNTrk();
260 m_hnTrk->Fill( nTrk );
261 m_fevt << setw( 10 ) << iRun << setw( 10 ) << iEvt << setw( 10 ) << nTrk << endl;
262 if ( ( nTrk < m_param.nTrkCut[0] ) || ( nTrk > m_param.nTrkCut[1] ) )
268 for ( i = 0; i < nTrk; i++ )
270 rectrk =
event->getRecTrk( i );
276 dr = rectrk->
getDr();
277 if ( fabs( dr ) > m_param.drCut )
287 dz = rectrk->
getDz();
288 if ( fabs( dz ) > m_param.dzCut )
294 for ( lay = 0; lay <
LAYERNMAX; lay++ ) { fgHitLay[lay] =
false; }
296 m_hnHit->Fill( nhits );
297 for ( k = 0; k < nhits; k++ )
301 fgHitLay[lay] =
true;
307 if ( fgHitLay[lay] ) nhitlay++;
310 if ( nhitlay < m_param.nHitLayCut )
319 pt = rectrk->
getPt();
321 if ( ( fabs( pt ) < m_param.ptCut[0] ) || ( fabs( pt ) > m_param.ptCut[1] ) )
327 HepVector helix = rectrk->
getHelix();
328 for ( k = 0; k < nhits; k++ )
333 lr = rechit->
getLR();
338 if ( ( 1 == m_param.hitStatCut ) && ( 1 != stat ) )
344 if ( 1 == m_param.resiType ) { resi = rechit->
getResiExcLR(); }
348 if ( ( 1 == std::isnan( resi ) ) || ( fabs( resi ) > m_resiCut ) ||
349 ( fabs( doca ) > m_docaMax[lay] ) || ( fabs( doca ) < m_docaMin[lay] ) )
355 if ( m_param.fgAdjacLayerCut )
365 else if ( 42 == lay )
375 if ( ( !fgHitLay[lay - 1] ) && ( !fgHitLay[lay + 1] ) )
381 if ( m_param.fgBoundLayerCut && m_layBound[lay] &&
382 ( ( !fgHitLay[lay - 1] ) || ( !fgHitLay[lay + 1] ) ) )
389 m_hlayHitmap->Fill( lay );
392 if ( ( zhit < m_zrange[lay][0] ) || ( zhit > m_zrange[lay][1] ) )
394 wir = m_mdcGeomSvc->Wire( lay, cel )->Id();
395 xx = ( zhit - m_zw[wir] ) * ( m_xe[wir] - m_xw[wir] ) / ( m_ze[wir] - m_zw[wir] ) +
397 yy = ( zhit - m_zw[wir] ) * ( m_ye[wir] - m_yw[wir] ) / ( m_ze[wir] - m_zw[wir] ) +
399 rr = sqrt( ( xx * xx ) + ( yy * yy ) );
400 dphi = fabs( doca ) / m_radii[lay];
402 if ( yy >= 0 ) wphi = acos( xx / rr );
403 else wphi =
PI2 - acos( xx / rr );
404 if ( 1 == lr ) hitPhi = wphi + dphi;
405 else hitPhi = wphi - dphi;
406 if ( hitPhi < 0 ) hitPhi +=
PI2;
407 else if ( hitPhi >
PI2 ) hitPhi -=
PI2;
409 if ( zhit < m_zrange[lay][0] ) iEnd = 0;
422 m_tuple[iEP]->write();
431 m_tuple[
NEP]->write();
433 m_hresAll->Fill( resi );
434 if ( lay < 8 ) m_hresInn->Fill( resi );
435 else if ( lay < 20 ) m_hresStp->Fill( resi );
436 else m_hresOut->Fill( resi );
437 m_hresLay[lay]->Fill( resi );
440 if ( hitPhi < 3.14 ) m_hresLay_LR[lay][0]->Fill( resi );
441 else m_hresLay_LR[lay][2]->Fill( resi );
445 if ( hitPhi < 3.14 ) m_hresLay_LR[lay][1]->Fill( resi );
446 else m_hresLay_LR[lay][3]->Fill( resi );
449 m_gr[iEP]->SetPoint( m_npoint[iEP], hitPhi, resi );
460 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc );
461 MsgStream log(
msgSvc,
"ResiAlign" );
462 log << MSG::INFO <<
"ResiAlign::updateConst()" << endmsg;
471 double rLayer[] = { 120.225, 205.0, 237.55, 270.175, 302.625, 334.775, 366.65, 500.0,
472 120.225, 205.0, 237.55, 270.175, 302.625, 334.775, 366.65, 500.0 };
474 TCanvas c1(
"c1",
"c1", 10, 10, 700, 500 );
476 TF1* fResPhi =
new TF1(
"fResPhi",
funResi, 0,
PI2, 3 );
477 fResPhi->SetParameter( 0, 0.0 );
478 fResPhi->SetParameter( 1, 0.0 );
479 fResPhi->SetParameter( 2, 0.0 );
481 for ( iEP = 0; iEP <
NEP; iEP++ )
483 if ( ( m_gr[iEP]->GetN() ) > 500 )
485 m_gr[iEP]->Fit(
"fResPhi",
"V" );
486 par[0] = fResPhi->GetParameter( 0 );
487 par[1] = fResPhi->GetParameter( 1 );
488 par[2] = fResPhi->GetParameter( 2 );
490 err[0] = fResPhi->GetParError( 0 );
491 err[1] = fResPhi->GetParError( 1 );
492 err[2] = fResPhi->GetParError( 2 );
496 rz = par[0] / rLayer[iEP];
499 if ( 7 == iEP || 15 == iEP )
514 alignPar->
setErrRz( iEP, err[0] / rLayer[iEP] );
518 cout <<
"TrackCut: cut1: " << m_ncut1 <<
", cut2: " << m_ncut2 <<
", cut3: " << m_ncut3
519 <<
", cut4: " << m_ncut4 <<
", cut5: " << m_ncut5 <<
", cut6: " << m_ncut6
520 <<
", cut7: " << m_ncut7 << endl;
521 cout <<
"HitCut: cut8: " << m_ncut8 <<
", cut9: " << m_ncut9 <<
", cut10: " << m_ncut10
522 <<
", cut11: " << m_ncut11 <<
", cut12: " << m_ncut12 <<
", cut13: " << m_ncut13