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