ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalChi2AlignTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include "CLHEP/Matrix/Matrix.h"
7#include "CLHEP/Matrix/SymMatrix.h"
8#include "CLHEP/Matrix/DiagMatrix.h"
9
10#include "GaudiKernel/StatusCode.h"
11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/AlgTool.h"
13
14#include "TrkTrack/Track.h"
19
26
29
30#include "TTree.h"
31#include "TFile.h"
32#include "TMatrixD.h"
33
34namespace Trk {
35
36 //_______________________________________________________________________
37 GlobalChi2AlignTool::GlobalChi2AlignTool(const std::string& type, const std::string& name,
38 const IInterface* parent)
39 : AthAlgTool(type,name,parent)
40 {
41 declareInterface<IAlignTool>(this);
42 m_logStream = nullptr;
43 }
44
45 //_______________________________________________________________________
47 {
48 ATH_MSG_DEBUG("in GlobalChi2AlignTool d'tor");
49 //delete m_tree;
50
51 delete [] m_chamberIds;
52 delete [] m_matrixIndices;
53 delete [] m_secndDeriv;
54 delete [] m_firstDeriv;
55 delete [] m_actualSecndDeriv;
56
57 ATH_MSG_DEBUG("done with GlobalChi2AlignTool d'tor");
58 }
59
60 //_______________________________________________________________________
62 {
63 ATH_MSG_DEBUG("initialize() of GlobalChi2AlignTool");
64 // Get MatrixTool
65 ATH_CHECK( m_matrixTool.retrieve() );
66 ATH_CHECK(m_alignModuleTool.retrieve() );
67 return StatusCode::SUCCESS;
68 }
69
70 //________________________________________________________________________
71 void GlobalChi2AlignTool::setLogStream(std::ostream * os)
72 {
73 m_logStream = os;
74 m_matrixTool->setLogStream(m_logStream);
75 }
76
77 //________________________________________________________________________
79 {
80 ATH_MSG_DEBUG("in GlobalGhi2AlignTool::firstEventInitialize()");
81
82 int nDoF=m_alignModuleTool->nAlignParameters();
83 ATH_MSG_DEBUG("allocating matrix with "<<nDoF<<" degrees of freedom");
84
85 if( m_matrixTool->allocateMatrix(nDoF).isFailure()) {
86 msg(MSG::FATAL)<<"Problem with allocateMatrix"<<endmsg;
87 return StatusCode::FAILURE;
88 }
89 ATH_MSG_DEBUG("done with firstEventInitialize()");
90
91 return StatusCode::SUCCESS;
92 }
93
94 //________________________________________________________________________
96 {
97 ATH_MSG_DEBUG("in GlobalChi2AlignTool::accumulate()");
98
99 // prepare ROOT tree for derivatives if it doesn't exist yet
100 // Shouldn't this be in firstEventInitialize() ?
101 if (m_doTree && !m_tree && m_ntuple) {
102
103 m_ntuple->cd();
104 m_tree=new TTree("globalChi2Deriv","globalChi2Deriv");
105 m_tree->Branch("run", &m_run, "run/I");
106 m_tree->Branch("event", &m_event, "event/I");
107 m_tree->Branch("nChambers", &m_nChambers, "nChambers/I");
108 m_tree->Branch("chamberIds", m_chamberIds, "chamberIds[nChambers]/I");
109 m_tree->Branch("nMatrixIndices", &m_nMatrixIndices, "nMatrixIndices/I");
110 m_tree->Branch("matrixIndices", m_matrixIndices, "matrixIndices[nMatrixIndices]/I");
111 m_tree->Branch("nSecndDeriv", &m_nSecndDeriv, "nSecndDeriv/I");
112 m_tree->Branch("secndDeriv", m_secndDeriv, "secndDeriv[nSecndDeriv]/D");
113 m_tree->Branch("firstDeriv", m_firstDeriv, "firstDeriv[nMatrixIndices]/D");
115 m_tree->Branch("actualSecndDeriv", m_actualSecndDeriv, "actualSecndDeriv[nMatrixIndices]/D");
116
117 m_tree->Branch("materialOnTrack", &m_materialOnTrack, "materialOnTrack/D");
118 m_tree->Branch("momentum", &m_momentum, "momentum/D");
119 m_tree->Branch("eta", &m_eta, "eta/D");
120 m_tree->Branch("phi", &m_phi, "phi/D");
121 m_tree->Branch("perigee_x", &m_perigee_x, "perigee_x/D");
122 m_tree->Branch("perigee_y", &m_perigee_y, "perigee_y/D");
123 m_tree->Branch("perigee_z", &m_perigee_z, "perigee_z/D");
124 m_tree->Branch("trackInfo", &m_trackInfo, "trackInfo/I");
125 m_tree->Branch("bremFit", &m_bremFit, "bremFit/I");
126 m_tree->Branch("bremFitSuccessful", &m_bremFitSuccessful, "bremFitSuccessful/I");
127 m_tree->Branch("straightTrack", &m_straightTrack, "straightTrack/I");
128 m_tree->Branch("slimmedTrack", &m_slimmedTrack, "slimmedTrack/I");
129 m_tree->Branch("hardScatterOrKink", &m_hardScatterOrKink, "hardScatterOrKink/I");
130 m_tree->Branch("lowPtTrack", &m_lowPtTrack, "lowPtTrack/I");
131 }
132
133
134 // check if the track belongs to a vertex. If yes, retrieve the relevant objects:
135 bool fullVertex = false;
136 AlignVertex * ptrVertex = alignTrack->getVtx();
137 const Amg::Vector3D * ptrPosition = nullptr;
138 const AmgSymMatrix(3) * ptrCovariance = nullptr;
139 const std::vector<AlignModuleVertexDerivatives> * ptrX = nullptr;
141 if( ptrVertex ) {
142 fullVertex = true;
143 ptrPosition = ptrVertex->position();
144 ptrCovariance = ptrVertex->covariance();
145 ptrX = ptrVertex->derivatives();
146 vtxType = ptrVertex->type();
147
148 // check if pointers are valid
149 if ( !ptrPosition || !ptrCovariance || !ptrX || vtxType<AlignVertex::Refitted ) {
150 msg(MSG::ERROR)<<"something missing from alignVertex!"<<endmsg;
151 if (!ptrPosition) msg(MSG::ERROR)<<"no fitted position!"<<endmsg;
152 if (!ptrCovariance) msg(MSG::ERROR)<<"no covariance!"<<endmsg;
153 if (!ptrX) msg(MSG::ERROR)<<"no link to the X object!"<<endmsg;
154 if (vtxType<AlignVertex::Refitted) msg(MSG::ERROR)<<"Vertex type = "<< vtxType << endmsg;
155 return false;
156 }
157 }
158
159
160
161 // reset tree variables
162 m_nChambers=0;
164
165 // get pointers so we can reuse them if they're valid
166 const Amg::SymMatrixX * ptrWeights = alignTrack->weightMatrix();
167 const Amg::SymMatrixX * ptrWeightsFD = alignTrack->weightMatrixFirstDeriv();
168 const Amg::VectorX * ptrResiduals = alignTrack->residualVector();
169 const std::vector<AlignModuleDerivatives> * ptrDerivs = alignTrack->derivatives();
170
171 // check if pointers are valid
172 if (!ptrWeights || !ptrWeightsFD || !ptrResiduals || !ptrDerivs) {
173 msg(MSG::ERROR)<<"something missing from alignTrack!"<<endmsg;
174 if (!ptrWeights) msg(MSG::ERROR)<<"no weights!"<<endmsg;
175 if (!ptrWeightsFD) msg(MSG::ERROR)<<"no weights for first deriv!"<<endmsg;
176 if (!ptrResiduals) msg(MSG::ERROR)<<"no residuals!"<<endmsg;
177 if (!ptrDerivs) msg(MSG::ERROR)<<"no derivatives!"<<endmsg;
178 return false;
179 }
180
181 // get weight matrices
182 const Amg::SymMatrixX& weights = *ptrWeights;
183 const Amg::SymMatrixX& weightsFirstDeriv = *ptrWeightsFD;
184 ATH_MSG_VERBOSE("weights="<<weights);
185 ATH_MSG_VERBOSE("weightsFirstDeriv="<<weightsFirstDeriv);
186
187 // get vectors
188 const Amg::VectorX& residuals = *ptrResiduals;
189 std::vector<AlignModuleDerivatives> derivatives = *ptrDerivs;
190 const std::vector<AlignModuleDerivatives>* derivativeErr = alignTrack->derivativeErr();
191 const std::vector<std::pair<AlignModule*,std::vector<double> > >* secDerivs = alignTrack->actualSecondDerivatives();
192
193
194
195 std::vector<AlignPar*> allAlignPars;
196 std::vector<Amg::VectorX*> allDerivatives;
197 std::vector<const Amg::VectorX*> allDerivativeErr;
198 std::vector<double> allActualSecDeriv;
199 int WSize(weights.cols());
200 Amg::MatrixX matrix_F(3,WSize );
201 matrix_F.setZero();
202
203 // get all alignPars and all derivatives
204 msg(MSG::DEBUG) << "accumulate: The derivative vector size is " << derivatives.size() << endmsg;
205 std::vector<AlignModuleDerivatives>::iterator derivIt = derivatives.begin();
206 std::vector<AlignModuleDerivatives>::iterator derivIt_end = derivatives.end();
207
208 std::vector<AlignModuleDerivatives>::const_iterator derivErrIt;
209 std::vector<std::pair<AlignModule*,std::vector<double> > >::const_iterator secDerivIt;
210 if (derivativeErr) derivErrIt=derivativeErr->begin();
211 if (secDerivs) secDerivIt=secDerivs->begin();
212 for ( ; derivIt!=derivIt_end ; ++derivIt) {
213
214 // get AlignModule
215 AlignModule* module=derivIt->first;
216
217 // increment track counter
218 module->addTrack();
219 ATH_MSG_DEBUG("add track to module "<<module->identify().get_identifier32().get_compact());
220 module->addNDoF(alignTrack->fitQuality()->numberDoF());
221 module->addTrackChi2(alignTrack->fitQuality()->chiSquared());
222
223 // tree variables
225 m_chamberIds[m_nChambers]=module->identify().get_identifier32().get_compact();
226 m_nChambers++;
227 }
228 else ATH_MSG_WARNING("number of chambers exceeded maximum");
229
230 // get alignment parameters
231 std::vector<Amg::VectorX>& deriv_vec = derivIt->second;
232 ATH_MSG_DEBUG( "accumulate: The deriv_vec size is " << deriv_vec.size() );
233 DataVector<AlignPar>* alignPars = m_alignModuleTool->getAlignPars(module);
234 int nModPars = alignPars->size();
235 if (nModPars != (int)deriv_vec.size() && (nModPars+3) != (int)deriv_vec.size()) {
236 ATH_MSG_ERROR("accumulate: wrong size of the deriv_vec!");
237 return false;
238 }
239 for (int i=0;i<3;i++) {
240 for (int j=0;j<WSize;j++) {
241 matrix_F(i,j) += deriv_vec[nModPars+i][j]; // in the derivIT loop the complete F matrix is built
242 }
243 }
244
245 // get derivatives and derivative errors
246 for (int i=0;i<nModPars;i++) {
247 ATH_MSG_DEBUG("align par for module "<<(*alignPars)[i]->alignModule()->identify());
248 allAlignPars.push_back((*alignPars)[i]);
249 allDerivatives.push_back(&deriv_vec[i]);
250 if (derivativeErr)
251 allDerivativeErr.push_back(&(derivErrIt->second)[i]);
252 if (secDerivs)
253 allActualSecDeriv.push_back((secDerivIt->second)[i]);
254 }
255 if (derivativeErr) ++derivErrIt;
256 if (secDerivs) ++secDerivIt;
257 }
258
259 // increment hit counters in modules
260 AlignTSOSCollection::iterator iatsos = alignTrack->firstAtsos();
261 AlignTSOSCollection::iterator iatsos_last = alignTrack->lastAtsos();
262 for (; iatsos != iatsos_last; ++iatsos)
263 if ((*iatsos)->module())
264 (*iatsos)->module()->addHit();
265
266 // determine all derivatives and set in matrix tool
267 int nAllPars = allAlignPars.size();
269 for (int ipar=0;ipar<nAllPars;ipar++) {
270
271 // calculate first derivative
272 Amg::MatrixX derivativesT = (*allDerivatives[ipar]).transpose();
273 ATH_MSG_DEBUG("derivativesT (size "<<derivativesT.cols()<<"): "<<derivativesT);
274
275 Amg::MatrixX RHM= weightsFirstDeriv * residuals;
276 ATH_MSG_DEBUG("RHM: "<<RHM);
277
278 // get global parameter index
279 int index1 = allAlignPars[ipar]->index();
280
281 Amg::MatrixX firstderivM = 2.* derivativesT * RHM;
282 ATH_MSG_DEBUG("firstderivM for i="<<index1 <<firstderivM);
283 if (firstderivM(0,0)==0.) {
284 ATH_MSG_DEBUG("firstderivM[0][0] is zero : "<<firstderivM(0,0));
285 continue;
286 }
287
288
289
290 // tree variables
293 ATH_MSG_DEBUG("ipar: "<<ipar<<", m_nMatrixIndices="<<m_nMatrixIndices);
295 ATH_MSG_DEBUG("alActualSecDeriv size: "<<allActualSecDeriv.size());
296 m_actualSecndDeriv[m_nMatrixIndices]=allActualSecDeriv[ipar];
297 }
299 }
300
301 // get module index
302 int imodule1 = allAlignPars[ipar]->alignModule()->identifyHash();
303
304 // calculate second derivatives
305 bool goodSecondDeriv = true;
306 for (int jpar=ipar;jpar<nAllPars;jpar++) {
307
308 // get global parameter index
309 int index2=allAlignPars[jpar]->index();
310
311 // get module index
312 int imodule2 = allAlignPars[jpar]->alignModule()->identifyHash();
313
314 // if only local Chi2 method is used, the 2nd derivatives (correlations)
315 // between different modules don't need to be calculated/stored
317 if (imodule1 != imodule2)
318 continue;
319
320 Amg::MatrixX RHM2 = weights * (*allDerivatives[jpar]);
321 Amg::MatrixX secondderivM = 2. * derivativesT * RHM2;
322
323 // if second derivative on diagonal is below cut
324 // ignore the whole row/column
325 if (jpar==ipar && secondderivM(0,0)<0.) {
326 ATH_MSG_WARNING("second deriv < 0 !!!");
327 }
328 if (jpar==ipar && secondderivM(0,0)<m_secondDerivativeCut) {
329 ATH_MSG_DEBUG("secondderivM[0][0] is below threshold : "<<
330 secondderivM(0,0)<<" < "<<m_secondDerivativeCut);
331 goodSecondDeriv = false;
332 break;
333 }
334
335 ATH_MSG_DEBUG("secondderivM for i "<<index1<<", j "<<index2<<": "<<secondderivM(0,0));
336 m_matrixTool->addSecondDerivative(index1, index2, secondderivM(0,0));
337
338 // store derivatives and indices for ntuple
339 m_secndDeriv[m_nSecndDeriv]=secondderivM(0,0);
341 }
342
343 // if second derivative on diagonal didn't pass the cut,
344 // ignore also the first derivative
345 if (goodSecondDeriv) {
346 m_matrixTool->addFirstDerivative(index1, firstderivM(0,0));
347 m_firstDeriv[ipar]=firstderivM(0,0);
348 }
349 else
350 m_firstDeriv[ipar]=-999.;
351 }
352
353
354
355
356 if( fullVertex ) { // this track is associated to a vertex.
357
358
359 ATH_MSG_DEBUG( "accumulate: Contribution from the fullVTX will be added " );
360
361 Amg::MatrixX RHM = (*ptrCovariance) * (matrix_F) * (weightsFirstDeriv * residuals);
362
363 std::vector<AlignPar*> vtxAlignPars;
364 std::vector<const Amg::VectorX*> vtxDerivatives;
365
366 // get all alignPars and all derivatives
367 msg(MSG::DEBUG) << "accumulate: The Vertex derivative vector size is " << ptrX->size() << endmsg;
368 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt = ptrX->begin();
369 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt_end = ptrX->end();
370
371 for ( ; XIt!=XIt_end ; ++XIt) {
372
373 // get AlignModule
374 const AlignModule* module=XIt->first;
375
376 // get alignment parameters
377 const std::vector<Amg::VectorX>& X_vec = XIt->second;
378 msg(MSG::DEBUG) << "accumulate: The X_vec size is " << X_vec.size() << endmsg;
379 DataVector<AlignPar>* alignPars = m_alignModuleTool->getAlignPars(module);
380 int nModPars = alignPars->size();
381 if (nModPars != (int)X_vec.size()) {
382 ATH_MSG_ERROR("accumulate: wrong size of the X_vec!");
383 return false;
384 }
385
386 // get derivatives and derivative errors
387 for (int i=0;i<nModPars;i++) {
388 ATH_MSG_DEBUG("align par for module "<<(*alignPars)[i]->alignModule()->identify());
389 vtxAlignPars.push_back((*alignPars)[i]);
390 vtxDerivatives.push_back(&X_vec[i]);
391 }
392
393 }
394
395 // bit responsible for the constraint:
396 int ierr(0);
397 AmgSymMatrix(3) Qinv;
398 Qinv.setZero();
399 Amg::Vector3D vtemp;
400 vtemp.setZero();
401 if( vtxType==AlignVertex::Refitted && ptrVertex->Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) { // just my guess sigma>0.1 micron ???) only once per vertex!
402
403 bool invertible;
404 double determinant;
405 ptrVertex->Qmatrix()->computeInverseAndDetWithCheck(Qinv,determinant,invertible);
406
407 if(!invertible) {
408 std::cout <<"accumulate: Q inversion failed. CLHEP status flag = "<<ierr<< std::endl;
409 return false;
410 }
411 vtemp(0) = -ptrVertex->originalPosition()->x()+(*(ptrVertex->Vvector()))(0);
412 vtemp(1) = -ptrVertex->originalPosition()->y()+(*(ptrVertex->Vvector()))(1);
413 vtemp(2) = -ptrVertex->originalPosition()->z()+(*(ptrVertex->Vvector()))(2);
414 }
415
416
417 // determine all derivatives and set in matrix tool
418 int nvtxPars = vtxAlignPars.size();
419 for (int ipar=0;ipar<nvtxPars;ipar++) {
420
421 // calculate first derivative
422 Amg::MatrixX derivativesT = (*vtxDerivatives[ipar]).transpose();
423 Amg::MatrixX firstderivM = -2.* derivativesT * RHM; // -2 seems correct :)
424
425 // bit responsible for the constraint:
426 if( vtxType==AlignVertex::Refitted && ptrVertex->Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) { // just my guess sigma>0.1 micron ???) only once per vertex!
427 firstderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv) * vtemp;
428 }
429
430 // get global parameter index
431 int index1 = vtxAlignPars[ipar]->index();
432
433 ATH_MSG_DEBUG("vtx firstderivM for i="<<index1 <<firstderivM);
434
435
436 if( vtxType==AlignVertex::Refitted ) { // only once per vertex!
437 ATH_MSG_DEBUG("accumulate: Filling second derivative for this vertex... ");
438 for (int jpar=0;jpar<nvtxPars;jpar++) {
439
440 // calculate second derivative
441 Amg::MatrixX secondderivM = -1.* derivativesT * (*ptrCovariance) * (*vtxDerivatives[jpar]); // -1 is the right factor :)
442
443 // bit responsible for the constraint:
444 if( ptrVertex->Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) { // just my guess sigma>0.1 micron ???)
445 secondderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv * (*ptrCovariance)) * (*vtxDerivatives[jpar]);
446 }
447
448 // get global parameter index
449 int index2=vtxAlignPars[jpar]->index();
450
451 if( index1<=index2 ) {
452 ATH_MSG_DEBUG("vtx secondderivM for i="<<index1<<", j="<<index2<<": "<<secondderivM(0,0));
453 m_matrixTool->addSecondDerivative(index1, index2, secondderivM(0,0));
454 }
455
456 }
457 ptrVertex->setType(AlignVertex::Accumulated); // only once per vertex!
458 }
459
460 m_matrixTool->addFirstDerivative(index1, firstderivM(0,0));
461
462 }
463
464 }
465
466
467
468
469
470 // fill tree
471 if (m_tree) {
472
473 // get tree variables
474 const xAOD::EventInfo* currentEvent;
475 StatusCode sc = evtStore()->retrieve(currentEvent);
476 if (sc==StatusCode::SUCCESS) {
477 m_run = currentEvent->runNumber();
478 m_event = currentEvent->eventNumber();
479 }
480 else {
481 m_run = -999;
482 m_event = -999;
483 }
484
486 ATH_MSG_DEBUG("materialOnTrack: "<<m_materialOnTrack);
487
488 double pT=alignTrack->originalTrack()->perigeeParameters()->pT();
489 double eta=alignTrack->originalTrack()->perigeeParameters()->eta();
490 m_momentum=std::fabs(pT)*std::sqrt(1.+sinh(eta)*sinh(eta));
491 m_eta=eta;
492 m_phi=alignTrack->originalTrack()->perigeeParameters()->momentum().phi();
493
495 m_perigee_x=pos.x();
496 m_perigee_y=pos.y();
497 m_perigee_z=pos.z();
498
499 const TrackInfo info=alignTrack->originalTrack()->info();
500 m_trackInfo = (int)info.trackFitter();
501 m_bremFit = (int)info.trackProperties(Trk::TrackInfo::BremFit);
502 m_bremFitSuccessful = (int)info.trackProperties(Trk::TrackInfo::BremFitSuccessful);
503 m_straightTrack = (int)info.trackProperties(Trk::TrackInfo::StraightTrack);
504 m_slimmedTrack = (int)info.trackProperties(Trk::TrackInfo::SlimmedTrack);
505 m_hardScatterOrKink = (int)info.trackProperties(Trk::TrackInfo::HardScatterOrKink);
506 m_lowPtTrack = (int)info.trackProperties(Trk::TrackInfo::LowPtTrack);
507
508 m_ntuple->cd();
509 m_tree->Fill();
510 }
511
512 // increment total number of accumulated tracks, hits and the total chi2
513 m_ntracks++;
514 m_nmeas += alignTrack->nAlignTSOSMeas();
515 m_nhits += alignTrack->alignTSOSCollection()->size();
516 m_chi2 += alignTrack->fitQuality()->chiSquared();
517 m_nDoF += alignTrack->fitQuality()->numberDoF();
518
519 if(m_ntracks%50==0)
520 ATH_MSG_INFO(">>>> Number of accumulated tracks: "<<m_ntracks);
521
522 return true;
523 }
524
525 //________________________________________________________________________
527 {
528 ATH_MSG_DEBUG("in accumulate");
529 bool success = m_matrixTool->accumulateFromFiles();
530
531 if (!success) {
532 ATH_MSG_FATAL("failure in MatrixTool accumulateFromFiles");
533 return false;
534 }
535
536 m_fromFiles = true;
537
538 return true;
539 }
540
541 //________________________________________________________________________
543 {
544 if(m_fromFiles)
545 m_nhits = m_matrixTool->nHits();
546 else {
547 m_matrixTool->setNTracks(m_ntracks);
548 m_matrixTool->setNMeasurements(m_nmeas);
549 m_matrixTool->setNHits(m_nhits);
550 }
551
552 // print statistics
553 if(m_logStream) {
554 *m_logStream<<"*************************************************************"<<std::endl;
555 *m_logStream<<"****** Global Chi2 alignment solving ******"<<std::endl;
556 *m_logStream<<"*"<<std::endl;
557 if(!m_fromFiles)
558 *m_logStream<<"* number of accumulated tracks: "<<m_ntracks<<std::endl;
559 *m_logStream<<"* number of processed hits: "<<m_nhits<<std::endl;
560 if(!m_fromFiles) {
561 *m_logStream<<"* number of used measurements: "<<m_nmeas<<std::endl;
562 *m_logStream<<"* total chi2 / nDoF: "<<m_chi2<<" / "<<m_nDoF<<std::endl;
563 }
564 *m_logStream<<"*"<<std::endl;
565 *m_logStream<<"* number of alignable objects: "<<m_alignModuleTool->alignModules1D()->size()<<std::endl;
566 *m_logStream<<"* total number of alignment DoFs: "<<m_alignModuleTool->nAlignParameters()<<std::endl;
567 *m_logStream<<"*"<<std::endl;
568 }
569
570 ATH_MSG_INFO(">>>> -----------------------------------------------");
571 ATH_MSG_INFO(">>>> Total number of accumulated tracks: "<<m_ntracks);
572 ATH_MSG_INFO(">>>> -----------------------------------------------");
573
574 ATH_MSG_DEBUG("calling matrixTool->solve()");
575 if (m_matrixTool->solve()>0)
576 return StatusCode::SUCCESS;
577
578 return StatusCode::FAILURE;
579 }
580
581 //________________________________________________________________________
583 {
584 ATH_MSG_DEBUG("writing tree");
585 int success=1;
586 if (m_tree) {
587 m_ntuple->cd();
588 success = m_tree->Write();
589 }
590 return success>0 ? StatusCode::SUCCESS : StatusCode::FAILURE;
591 }
592
593 //_______________________________________________________________________
595 {
596 ATH_MSG_DEBUG("finalize() of GlobalChi2AlignTool");
597 return StatusCode::SUCCESS;
598 }
599
600 //________________________________________________________________________
602 {
603
604 double materialOnTrack(0.);
605
606 const Trk::TrackStates* states = track->trackStateOnSurfaces();
607 if ( !states ) {
608 ATH_MSG_WARNING("no states");
609 return 0;
610 }
611
612 // loop over TSOSs, find MDT hits, and mark them as outliers:
613 Trk::TrackStates::const_iterator tsit = states->begin();
614 Trk::TrackStates::const_iterator tsit_end = states->end();
615 ATH_MSG_DEBUG("looping over TSOS");
616
617 for ( ; tsit!=tsit_end ; ++tsit ) {
618 const Trk:: MaterialEffectsBase* materialEffects = (*tsit)->materialEffectsOnTrack();
619 if (materialEffects) {
620 const Trk::MaterialEffectsOnTrack* meot=dynamic_cast<const Trk::MaterialEffectsOnTrack*>(materialEffects);
621 if (meot) {
622 materialOnTrack += meot->thicknessInX0();
623 ATH_MSG_DEBUG("new materialOnTrack: "<<materialOnTrack);
624 }
625 else {
626 ATH_MSG_DEBUG("not material on track");
627 }
628 }
629 }
630
631 return materialOnTrack;
632 }
633
634} // end of namespace
635
Scalar eta() const
pseudorapidity method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define AmgSymMatrix(dim)
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
ServiceHandle< StoreGateSvc > & evtStore()
MsgStream & msg() const
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
size_type size() const noexcept
Returns the number of elements in the collection.
AlignTSOSCollection::const_iterator lastAtsos() const
returns iterator pointer to last element in collection
Definition AlignTrack.h:280
int nAlignTSOSMeas() const
number of alignTSOS (including scatterers if included on AlignTrack
Definition AlignTrack.h:128
const std::vector< AlignModuleDerivatives > * derivatives() const
The Amg::VectorX is a vector of first-derivatives of the alignTSOS on the alignTrack w....
Definition AlignTrack.h:133
const Track * originalTrack() const
retrieve pointer to original track
Definition AlignTrack.h:90
const Amg::VectorX * residualVector() const
Vector of residuals of the alignTSOS on the alignTrack, to be set by AlignTrackDresser.
Definition AlignTrack.h:150
const std::vector< std::pair< AlignModule *, std::vector< double > > > * actualSecondDerivatives() const
The Amg::VectorX is a vector of first-derivatives of the alignTSOS on the alignTrack w....
Definition AlignTrack.h:146
const std::vector< AlignModuleDerivatives > * derivativeErr() const
The Amg::VectorX is a vector of errors in first-derivatives of the alignTSOS on the alignTrack w....
Definition AlignTrack.h:140
AlignTSOSCollection::const_iterator firstAtsos() const
retrieve iterator pointer to first element in collection
Definition AlignTrack.h:279
const AlignTSOSCollection * alignTSOSCollection() const
returns collection of alignTSOS
Definition AlignTrack.h:267
const Amg::SymMatrixX * weightMatrixFirstDeriv() const
First deriv weight matrix can be either W from Si alignment (see Eqn.
Definition AlignTrack.h:161
const AlignVertex * getVtx() const
set and get pointer to the associated vertex
Definition AlignTrack.h:188
const Amg::SymMatrixX * weightMatrix() const
Weight matrix is W from Si alignment (see Eqn.
Definition AlignTrack.h:156
const Amg::Vector3D * originalPosition() const
Definition AlignVertex.h:79
@ Unknown
default type
Definition AlignVertex.h:44
@ Refitted
normally refitted, without adding any pseudo-measurement
Definition AlignVertex.h:46
@ Accumulated
accumulated by the GX algorithm.
Definition AlignVertex.h:47
const Amg::Vector3D * Vvector() const
bool Constrained() const
AlignVertexType type() const
get and set the refit type
Definition AlignVertex.h:85
const Amg::Vector3D * position() const
get the vertex position and covariance
Definition AlignVertex.h:89
void setType(AlignVertexType type)
Definition AlignVertex.h:86
const std::vector< AlignModuleVertexDerivatives > * derivatives() const
The Amg::VectorX is a vector of first-derivatives of the alignTSOS on the alignTrack w....
Definition AlignVertex.h:95
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition FitQuality.h:60
double chiSquared() const
returns the of the overall track fit
Definition FitQuality.h:56
PublicToolHandle< Trk::IAlignModuleTool > m_alignModuleTool
Pointer to AlignModuleTool.
unsigned int m_nhits
number of accumulated hits
bool accumulate(AlignTrack *alignTrack)
accumulates information from an AlignTrack
Gaudi::Property< bool > m_storeLocalDerivOnly
void setLogStream(std::ostream *os)
sets the output stream for the logfile
virtual ~GlobalChi2AlignTool()
Virtual destructor.
Gaudi::Property< bool > m_writeActualSecDeriv
StatusCode fillNtuple()
writes tree to ntuple
virtual StatusCode initialize()
initialize
TFile * m_ntuple
output ntuple
bool accumulateFromFiles()
accumulates information from binary files
unsigned int m_ntracks
number of accumulated tracks
double getMaterialOnTrack(const Trk::Track *track)
virtual StatusCode solve()
solves for alignment parameters
Gaudi::Property< double > m_secondDerivativeCut
static constexpr int MAXNCHAMBERS
ToolHandle< Trk::IMatrixTool > m_matrixTool
Pointer to MatrixTool, used to write to and solve matrix.
GlobalChi2AlignTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Gaudi::Property< bool > m_doTree
unsigned int m_nmeas
number of accumulated measurements
virtual StatusCode finalize()
finalize
virtual StatusCode firstEventInitialize()
sets up matrix
unsigned int m_nDoF
number of degrees of freedom
std::ostream * m_logStream
logfile output stream
Definition IAlignTool.h:54
double thicknessInX0() const
returns the actually traversed material .
represents the full description of deflection and e-loss of a track in material.
double eta() const
Access method for pseudorapidity - from momentum.
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
double pT() const
Access method for transverse momentum.
Contains information about the 'fitter' of this track.
@ BremFit
A brem fit was performed on this track.
@ HardScatterOrKink
A track with a kink or a hard scatter.
@ BremFitSuccessful
A brem fit was performed on this track and this fit was successful.
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
const Perigee * perigeeParameters() const
return Perigee.
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > SymMatrixX
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Ensure that the ATLAS eigen extensions are properly loaded.
DataVector< const Trk::TrackStateOnSurface > TrackStates
EventInfo_v1 EventInfo
Definition of the latest event info version.