ATLAS Offline Software
Loading...
Searching...
No Matches
Trk::ShiftingDerivCalcTool Class Reference

#include <ShiftingDerivCalcTool.h>

Inheritance diagram for Trk::ShiftingDerivCalcTool:
Collaboration diagram for Trk::ShiftingDerivCalcTool:

Public Types

enum  SolveOption {
  NONE = 0 , SOLVE = 1 , SOLVE_FAST = 2 , DIRECT_SOLVE = 3 ,
  DIRECT_SOLVE_FAST = 4 , DIRECT_SOLVE_CLUSTER = 5
}
 enum of different solving options More...

Public Member Functions

 ShiftingDerivCalcTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~ShiftingDerivCalcTool ()
StatusCode initialize ()
StatusCode finalize ()
bool setDerivatives (AlignTrack *track)
 sets derivatives of residuals w.r.t.
void showStatistics ()
 write statistics to log file
bool setResidualCovMatrix (AlignTrack *alignTrack) const
 sets residual covariance matrix
void setSolveOption (int solveOption)
 solving option (see enum above)
virtual void setLogStream (std::ostream *os)
 sets the output stream for the logfile
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID.

Protected Types

typedef std::vector< Amg::VectorXHitDerivative
typedef std::map< const TrackStateOnSurface *, HitDerivative * > DerivativeMap
typedef DerivativeMap::value_type DerivativePair

Protected Member Functions

Amg::VectorX getDerivatives (AlignTrack *alignTrack, int ipar, AlignPar *alignPar, Amg::VectorX &derivativeErr, bool &resetIPar, double &actualSecondDerivative)
void setChi2VAlignParam (const AlignTrack *alignTrack, const AlignModule *module, int nshifts=0)
void deleteChi2VAlignParam ()
double shiftSize (const AlignPar *alignPar) const
bool setUnshiftedResiduals (AlignTrack *alignTrack)
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Protected Attributes

std::ostream * m_logStream = nullptr
 logfile output stream

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

const Trk::TrackbestPerigeeTrack (const Track *track) const
bool scanShifts (const AlignTrack *alignTrack, const std::vector< AlignModule * > &alignModules)
bool getAllDerivatives (AlignTrack *alignTrack, const AlignModule *alignModule, std::vector< Amg::VectorX > &deriv_vec, std::vector< Amg::VectorX > &derivErr_vec, std::vector< double > &actualsecderiv_vec, bool &resetIPar)
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

ToolHandle< IGlobalTrackFitterm_trackFitterTool {this, "TrackFitterTool", "Trk::GlobalChi2Fitter/MCTBFitter"}
ToolHandle< IGlobalTrackFitterm_SLTrackFitterTool {this, "SLTrackFitterTool", "Trk::GlobalChi2Fitter/MCTBSLFitter"}
ToolHandle< IGlobalTrackFitterm_fitter
ToolHandle< IAlignResidualCalculatorm_residualCalculator {this, "ResidualCalculator", "Trk::AlignResidualCalculator/ResidualCalculator"}
ToolHandle< IAlignModuleToolm_alignModuleTool {this, "AlignModuleTool", "Trk::AlignModuleTool/AlignModuleTool"}
Gaudi::Property< double > m_traSize {this, "TranslationSize", .1}
Gaudi::Property< double > m_rotSize {this, "RotationSize", .1}
Gaudi::Property< bool > m_runOutlierRemoval {this, "RunOutlierRemoval", false}
ParticleHypothesis m_particleHypothesis = Trk::muon
Gaudi::Property< int > m_particleNumber {this, "ParticleNumber", 2}
DerivativeMap m_derivative_map
Gaudi::Property< bool > m_doFits {this, "doResidualFits", true}
Gaudi::Property< int > m_nFits {this, "NumberOfShifts", 5}
Gaudi::Property< bool > m_doChi2VAlignParamMeasType {this, "doChi2VChamberShiftsMeasType", false}
Gaudi::Property< bool > m_doResidualPlots {this, "doResidualPlots", false}
int m_nIterations = 0
Amg::VectorXm_unshiftedResiduals = nullptr
Amg::VectorXm_unshiftedResErrors = nullptr
std::vector< double ** > m_chi2VAlignParamVec
 track chi2[idof][ichambershift]
std::vector< double ** > m_chi2VAlignParamXVec
 chamber shift[idof][ichambershift]
double ** m_tmpChi2VAlignParam = nullptr
double ** m_tmpChi2VAlignParamX = nullptr
double *** m_tmpChi2VAlignParamMeasType = nullptr
std::vector< double *** > m_chi2VAlignParamVecMeasType
 track chi2[idof][imeastype][ichambershift]
double m_unshiftedTrackChi2 {}
std::unique_ptr< double[]> m_unshiftedTrackChi2MeasType
 cut on value of track alignment parameter, determined from fit of chi2 vs.
Gaudi::Property< double > m_trackAlignParamCut {this, "TrackAlignParamCut", 1e6}
 fit track with AlignModules shifted up and down in each extreme, find the number of iterations fitter uses to converge.
Gaudi::Property< bool > m_setMinIterations {this, "SetMinIterations", false}
 reject track if exceed maximum number of iterations
Gaudi::Property< int > m_maxIter {this, "MaxIterations", 50}
 set minimum number of iterations for first track fits
Gaudi::Property< int > m_minIter {this, "MinIterations", 10}
 flag to remove scattering before refitting track
Gaudi::Property< bool > m_removeScatteringBeforeRefit {this, "RemoveScatteringBeforeRefit", false}
int m_ntracksProcessed = 0
 number tracks processed
int m_ntracksPassInitScan = 0
 number tracks pass initial scan
int m_ntracksPassSetUnshiftedRes = 0
 number tracks pass setting unshifted residuals
int m_ntracksPassDerivatives = 0
 number tracks pass setting derivatives
int m_ntracksPassGetDeriv = 0
 number tracks pass getting derivatives
int m_ntracksPassGetDerivSecPass = 0
 number tracks pass 2nd pass of getting derivatives
int m_ntracksPassGetDerivLastPass = 0
 number tracks pass 2nd pass of getting derivatives
int m_ntracksFailMaxIter = 0
int m_ntracksFailTrackRefit = 0
int m_ntracksFailAlignParamCut = 0
int m_ntracksFailFinalAttempt = 0
bool m_secPass {}
int m_solveOption = 0
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 46 of file ShiftingDerivCalcTool.h.

Member Typedef Documentation

◆ DerivativeMap

Definition at line 68 of file ShiftingDerivCalcTool.h.

◆ DerivativePair

typedef DerivativeMap::value_type Trk::ShiftingDerivCalcTool::DerivativePair
protected

Definition at line 69 of file ShiftingDerivCalcTool.h.

◆ HitDerivative

Definition at line 67 of file ShiftingDerivCalcTool.h.

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Member Enumeration Documentation

◆ SolveOption

enum of different solving options

Enumerator
NONE 

not solve in any case (to be used when ipc)

SOLVE 

solving after data accumulation (LAPACK)

SOLVE_FAST 

Fast (Eigen method) solving after data accumulation.

DIRECT_SOLVE 

direct solving (LAPACK), already available matrix & vector

DIRECT_SOLVE_FAST 

direct Fast (Eigen method) solving, already available matrix & vector

DIRECT_SOLVE_CLUSTER 

computation of alignment parameters from SCALAPAK already solved matrix

Definition at line 41 of file IDerivCalcTool.h.

41 {
42 NONE = 0,
43 SOLVE = 1,
44 SOLVE_FAST = 2,
45 DIRECT_SOLVE = 3,
48 }; // this is also defined in TrkGlobAlign class
@ DIRECT_SOLVE_FAST
direct Fast (Eigen method) solving, already available matrix & vector
@ DIRECT_SOLVE_CLUSTER
computation of alignment parameters from SCALAPAK already solved matrix
@ SOLVE
solving after data accumulation (LAPACK)
@ SOLVE_FAST
Fast (Eigen method) solving after data accumulation.
@ NONE
not solve in any case (to be used when ipc)
@ DIRECT_SOLVE
direct solving (LAPACK), already available matrix & vector

Constructor & Destructor Documentation

◆ ShiftingDerivCalcTool()

ShiftingDerivCalcTool::ShiftingDerivCalcTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 35 of file ShiftingDerivCalcTool.cxx.

39 : AthAlgTool(type,name,parent)
41 {
42 declareInterface<IDerivCalcTool>(this);
43
44 m_logStream = nullptr;
45 }
AthAlgTool()
Default constructor:
std::ostream * m_logStream
logfile output stream
std::unique_ptr< double[]> m_unshiftedTrackChi2MeasType
cut on value of track alignment parameter, determined from fit of chi2 vs.

◆ ~ShiftingDerivCalcTool()

ShiftingDerivCalcTool::~ShiftingDerivCalcTool ( )
virtual

Definition at line 48 of file ShiftingDerivCalcTool.cxx.

Member Function Documentation

◆ bestPerigeeTrack()

const Trk::Track * Trk::ShiftingDerivCalcTool::bestPerigeeTrack ( const Track * track) const
private

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ deleteChi2VAlignParam()

void ShiftingDerivCalcTool::deleteChi2VAlignParam ( )
protected

Definition at line 854 of file ShiftingDerivCalcTool.cxx.

855{
856 for (int i=0;i<(int)m_chi2VAlignParamVec.size();i++) {
857 delete [] m_chi2VAlignParamVec[i]; m_chi2VAlignParamVec[i]=nullptr;
858 delete [] m_chi2VAlignParamXVec[i]; m_chi2VAlignParamXVec[i]=nullptr;
859 }
860 m_chi2VAlignParamVec.clear();
861 m_chi2VAlignParamXVec.clear();
862
863 for (auto & i : m_chi2VAlignParamVecMeasType) {
864 delete [] i; i=nullptr;
865 }
867}
std::vector< double ** > m_chi2VAlignParamVec
track chi2[idof][ichambershift]
std::vector< double *** > m_chi2VAlignParamVecMeasType
track chi2[idof][imeastype][ichambershift]
std::vector< double ** > m_chi2VAlignParamXVec
chamber shift[idof][ichambershift]

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ finalize()

StatusCode ShiftingDerivCalcTool::finalize ( )

Definition at line 82 of file ShiftingDerivCalcTool.cxx.

83 {
84 ATH_MSG_INFO("number tracks processed: "<<m_ntracksProcessed<<
85 "\nnumber tracks passing initial scan: "<<m_ntracksPassInitScan<<
86 "\nnumber tracks passing setting unshifted residuals: "<< m_ntracksPassSetUnshiftedRes<<
87 "\nnumber tracks pass getting derivatives (1st pass): "<<m_ntracksPassGetDeriv<<
88 "\nnumber tracks pass getting derivatives (2nd pass): "<<m_ntracksPassGetDerivSecPass<<
89 "\nnumber tracks pass getting derivatives (3rd pass): "<<m_ntracksPassGetDerivLastPass<<
90 "\nnumber tracks pass setting derivatives: "<<m_ntracksPassDerivatives);
91 ATH_MSG_INFO("number tracks fail max iterations: "<<m_ntracksFailMaxIter<<
92 "\nnumber tracks fail track refit: "<<m_ntracksFailTrackRefit<<
93 "\nnumber tracks fail align param cut: "<<m_ntracksFailAlignParamCut<<
94 "\nnumber tracks fail final attempt: "<<m_ntracksFailFinalAttempt);
95
96 return StatusCode::SUCCESS;
97 }
#define ATH_MSG_INFO(x)
int m_ntracksProcessed
number tracks processed
int m_ntracksPassSetUnshiftedRes
number tracks pass setting unshifted residuals
int m_ntracksPassInitScan
number tracks pass initial scan
int m_ntracksPassGetDeriv
number tracks pass getting derivatives
int m_ntracksPassGetDerivSecPass
number tracks pass 2nd pass of getting derivatives
int m_ntracksPassGetDerivLastPass
number tracks pass 2nd pass of getting derivatives
int m_ntracksPassDerivatives
number tracks pass setting derivatives

◆ getAllDerivatives()

bool ShiftingDerivCalcTool::getAllDerivatives ( AlignTrack * alignTrack,
const AlignModule * alignModule,
std::vector< Amg::VectorX > & deriv_vec,
std::vector< Amg::VectorX > & derivErr_vec,
std::vector< double > & actualsecderiv_vec,
bool & resetIPar )
private

Definition at line 870 of file ShiftingDerivCalcTool.cxx.

877{
878 resetIPar=false;
879
880 deriv_vec.clear();
881 derivErr_vec.clear();
882 actualsecderiv_vec.clear();
883
884 setUnshiftedResiduals(alignTrack); // this will set the min number of iterations to the new value
885
886 int ipar(0);
887 DataVector<AlignPar>* alignPars=m_alignModuleTool->getAlignPars(alignModule);
888 for (DataVector<AlignPar>::iterator it=alignPars->begin(); it!=alignPars->end(); ++it,ipar++) {
889 ATH_MSG_DEBUG("ipar: "<<ipar);
890 Amg::VectorX derivErr(alignTrack->nAlignTSOSMeas());
891 double actualSecondDeriv(0.);
892 const Amg::VectorX vec=getDerivatives(alignTrack,ipar,*it,derivErr,resetIPar,actualSecondDeriv);
893 ATH_MSG_DEBUG("vec size: "<<vec.rows());
894
895 ATH_MSG_DEBUG("resetIPar="<<resetIPar);
896 if (resetIPar) continue; // continue with derivatives to find max iteration
897
898 if (vec.rows()<1) return false; // derivatives won't be set for alignTrack because it's a bad track
899
900 deriv_vec.push_back(vec);
901 derivErr_vec.push_back(derivErr);
902 actualsecderiv_vec.push_back(actualSecondDeriv);
903
904 for (int i=0;i<m_nFits;i++) {
905 ATH_MSG_DEBUG("m_tmpChi2VAlignParam["<<ipar<<"]["
906 <<i<<"]="<<m_tmpChi2VAlignParam[ipar][i]);
907 }
908 }
909
910 return true;
911}
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
DataModel_detail::iterator< DataVector > iterator
Standard iterator.
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool setUnshiftedResiduals(AlignTrack *alignTrack)
Amg::VectorX getDerivatives(AlignTrack *alignTrack, int ipar, AlignPar *alignPar, Amg::VectorX &derivativeErr, bool &resetIPar, double &actualSecondDerivative)
ToolHandle< IAlignModuleTool > m_alignModuleTool
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.

◆ getDerivatives()

Amg::VectorX ShiftingDerivCalcTool::getDerivatives ( AlignTrack * alignTrack,
int ipar,
AlignPar * alignPar,
Amg::VectorX & derivativeErr,
bool & resetIPar,
double & actualSecondDerivative )
protected

Definition at line 430 of file ShiftingDerivCalcTool.cxx.

436{
437 const Trk::Track* trackForRefit =
438 (m_removeScatteringBeforeRefit) ? alignTrack->trackWithoutScattering():
439 dynamic_cast<const Trk::Track*>(alignTrack);
440
441 ATH_MSG_DEBUG("m_nIterations: "<<m_nIterations);
442
443 // gets derivatives of residuals w.r.t. a specific alignment parameter given by alignPar
444 if (!m_fitter)
445 ATH_MSG_ERROR("set m_fitter before calling getDerivatives (by calling setUnshiftedResiduals)");
446
447 AlignModule* module=alignPar->alignModule();
448
449 // set derivatives for 2 shifts up and 2 shifts down
450 const int NFITS = m_nFits;
451 const int NMEAS = alignTrack->nAlignTSOSMeas();
452 module->setNChamberShifts(m_nFits);
453
454 ATH_MSG_DEBUG("NMEAS="<<NMEAS);
455 double** residuals=new double*[NFITS];
456 double** resErrors=new double*[NFITS];
457 double* chi2Array =new double[NFITS];
458 double* chi2ArrayX=new double[NFITS];
459
462 m_tmpChi2VAlignParamMeasType[i][ipar] =new double[NFITS];
463 }
464
465 for (int ifit=0;ifit<NFITS;ifit++) {
466 residuals[ifit]=new double[NMEAS];
467 resErrors[ifit]=new double[NMEAS];
468 }
469
470 // set the values for the unshifted track
471 const int unshiftedTrackIndex = m_doFits ? (m_nFits-1)/2 : 1;
472 chi2Array [unshiftedTrackIndex] = m_unshiftedTrackChi2;
473 ATH_MSG_DEBUG("chi2Array["<<unshiftedTrackIndex<<"]="<<chi2Array[unshiftedTrackIndex]);
474 chi2ArrayX[unshiftedTrackIndex] = 0.;
477 m_tmpChi2VAlignParamMeasType[i][ipar][unshiftedTrackIndex]=
479 ATH_MSG_DEBUG("chi2ArrayMeasType["<<i<<"]["<<unshiftedTrackIndex<<"]="<<m_unshiftedTrackChi2MeasType[i]);
480 }
481 }
482
483
484 // get shift size
485 double shiftsize=shiftSize(alignPar);
486
487 IGlobalTrackFitter::AlignmentCache alignCache;
488
489
490 ATH_MSG_VERBOSE("doing refits");
491 for (int ifit=0;ifit<NFITS;ifit++) {
492
493 ATH_MSG_VERBOSE("ifit="<<ifit);
494 int jfit=ifit;
495 if (ifit>unshiftedTrackIndex) {
496 jfit=NFITS-ifit+unshiftedTrackIndex;
497 }
498 if (m_doFits && ifit==unshiftedTrackIndex) {
499 for (int i=0;i<(int)m_unshiftedResiduals->rows();i++) {
500 residuals[ifit][i]=(*m_unshiftedResiduals)[i];
501 resErrors[ifit][i]=(*m_unshiftedResErrors)[i];
502 }
503 // change back in case it got changed on the other side of zero
504 shiftsize=shiftSize(alignPar);
505 continue;
506 }
507
508 // shift module and fit track
509 double currentshift = 0.;
510 if(m_doFits)
511 currentshift = shiftsize * (double)(jfit-unshiftedTrackIndex);
512 else
513 currentshift = (ifit==0) ? -1.*shiftsize : shiftsize;
514
515 ATH_MSG_DEBUG("current shift="<<currentshift<<" in getDerivatives");
516
517 m_alignModuleTool->shiftModule(module,alignTrack,
518 alignPar->paramType(),currentshift);
519
520
521 ATH_MSG_VERBOSE("fitting after shift");
522 const Track* refittedTrack=m_fitter->alignmentFit(alignCache,
523 *trackForRefit,
525 if (m_setMinIterations && alignCache.m_iterationsOfLastFit>m_nIterations) {
526 m_nIterations=alignCache.m_iterationsOfLastFit;
528 ATH_MSG_DEBUG("exceeded max number of iterations");
529 m_alignModuleTool->restoreModule(module);
530 resetIPar=false;
531 ATH_MSG_DEBUG("resetIPar set to false");
532 delete [] residuals; delete [] resErrors;
533 delete [] chi2Array; delete [] chi2ArrayX;
534 ATH_MSG_DEBUG("fail max iter");
536 Amg::VectorX derivatives(1);
537 return derivatives;
538 }
539 ATH_MSG_DEBUG("increasing m_nIterations to "<<m_nIterations<<" (not changing in fit yet)");
540 resetIPar=true;
541 ATH_MSG_DEBUG("resetIPar set to true");
542 }
543
544 // if resetIPar refit the rest of the tracks, but don't do anything with them until next pass
545 if (resetIPar) {
546 m_alignModuleTool->restoreModule(module);
547 continue;
548 }
549
550 if (!refittedTrack) {
551 msg(MSG::WARNING) << "track refit failed for jfit "<<jfit <<endmsg;
552 delete [] residuals; delete [] resErrors;
553 delete [] chi2Array; delete [] chi2ArrayX;
554 m_alignModuleTool->restoreModule(module);
555 if (!resetIPar || m_secPass) {
557 }
558 ATH_MSG_DEBUG("fail track refit, resetIPar "<<resetIPar<<", secPass "<<m_secPass);
559 Amg::VectorX derivatives(1);
560 return derivatives;
561 }
562 else
563 ATH_MSG_VERBOSE("track refit successful");
564
565 double chi2=refittedTrack->fitQuality()->chiSquared();
566
567 ATH_MSG_VERBOSE("jfit = "<<jfit);
568 double localChi2=m_residualCalculator->setResiduals(alignTrack,refittedTrack);
569 ATH_MSG_DEBUG("localChi2/fittedChi2="<<localChi2<<"/"<<chi2);
570
571 chi2ArrayX[jfit]= shiftsize * (double)(jfit-unshiftedTrackIndex);// / module->sigma(idof);
572 chi2Array[jfit]=localChi2;
573 ATH_MSG_DEBUG("chi2Array["<<jfit<<"]="<<chi2Array[jfit]);
576 m_tmpChi2VAlignParamMeasType[i][ipar][jfit]= m_residualCalculator->chi2ForMeasType(i);
577 ATH_MSG_DEBUG("chi2ArrayMeasType["<<i<<"]["<<jfit<<"]="
578 <<m_tmpChi2VAlignParamMeasType[i][ipar][jfit]);
579 }
580 }
581
582 ATH_MSG_DEBUG("positions["<<jfit<<"]="<<chi2ArrayX[jfit]);
583
584 int imeas(0);
585 AlignTSOSCollection::const_iterator atsosItr=alignTrack->firstAtsos();
586 for (; atsosItr != alignTrack->lastAtsos(); ++atsosItr) {
587 if (!(*atsosItr)->isValid()) continue;
588 for (std::vector<Residual>::const_iterator itRes=(**atsosItr).firstResidual();
589 itRes!=(**atsosItr).lastResidual();++itRes,++imeas) {
590
591 if (refittedTrack) {
592 residuals[jfit][imeas]=itRes->residual();
593 resErrors[jfit][imeas]=std::sqrt(itRes->errSq());
594 }
595 else {
596 residuals[jfit][imeas]=resErrors[jfit][imeas]=0.;
597 }
598 ATH_MSG_DEBUG("residuals["<<jfit<<"]["<<imeas<<"]="<<residuals[jfit][imeas]);
599 ATH_MSG_DEBUG("resErrors["<<jfit<<"]["<<imeas<<"]="<<resErrors[jfit][imeas]);
600 }
601 }
602
603 delete refittedTrack; refittedTrack=nullptr;
604 ATH_MSG_VERBOSE("calling restoreModule");
605 m_alignModuleTool->restoreModule(module);
606 } // NFITS
607
608 int iimeas(0);
609 AlignTSOSCollection::const_iterator aatsosItr=alignTrack->firstAtsos();
610 for (; aatsosItr != alignTrack->lastAtsos(); ++aatsosItr) {
611 if (!(*aatsosItr)->isValid()) continue;
612 for (std::vector<Residual>::const_iterator itRes=(**aatsosItr).firstResidual();
613 itRes!=(**aatsosItr).lastResidual();++itRes,++iimeas) {
614 for (int ifit=0;ifit<NFITS;ifit++) {
615 ATH_MSG_DEBUG("["<<ifit<<"]["<<iimeas<<"] res="<<residuals[ifit][iimeas]<<
616 ", resErr="<<resErrors[ifit][iimeas]);
617 }
618 }
619 }
620
621 if (resetIPar) {
622 //resetIPar=false;
623 delete [] residuals; delete [] resErrors;
624 delete [] chi2Array; delete [] chi2ArrayX;
625 if (m_secPass) ATH_MSG_WARNING("failed second pass!");
626 ATH_MSG_DEBUG("returning to reset IPar");
627 Amg::VectorX derivatives;
628 return derivatives;
629 }
630
631 // check chi2 vs. chamber pos to see if discontinuous
632 TGraph* gr = new TGraph(m_nFits,chi2ArrayX,chi2Array);
633 gr->Fit("pol2","QF");
634 TF1* fit=gr->GetFunction("pol2");
635 double chi2 =fit->GetChisquare()/double(m_nFits-3);
636 double slope=fit->GetParameter(1);
637 actualSecondDeriv=fit->GetParameter(2);
638 delete gr;
639
640 ATH_MSG_DEBUG("discontinuity check: chi2="<<chi2);
641 alignTrack->setTrackAlignParamQuality(alignPar->paramType(),chi2);
642
643 // EventInfo
644 if (chi2>1.e-6 || std::fabs(slope)<1.e-10) {
645 const xAOD::EventInfo* eventInfo;
646 StatusCode sc=evtStore()->retrieve(eventInfo);
647 if (sc.isFailure())
648 ATH_MSG_ERROR("Couldn't retrieve event info");
649 int run=eventInfo->runNumber();
650 int evt=eventInfo->eventNumber();
651 ATH_MSG_DEBUG("discontinuity check: chi2="<<chi2<<", run/evt "<<run<<"/"<<evt);
652 }
653
654 //reset in case it got changed somewhere
655 shiftsize = shiftSize(alignPar);
656
657 //-----------------------------------------//
658 //-- get derivatives from residuals --//
659 //-----------------------------------------//
660 ATH_MSG_VERBOSE("calculating residuals");
661 Amg::VectorX derivatives(alignTrack->nAlignTSOSMeas(),0);
662 ATH_MSG_DEBUG("created derivatives with "<<derivatives.rows()<<" rows");
663
664 // if bad fit or first derivative close to zero, replace derivatives with zeros
665 if (chi2>m_trackAlignParamCut) {// || std::fabs(slope)<1.e-10 ) {
666 ATH_MSG_DEBUG("chi2/"<<m_nFits-3<<"="<<chi2);
667 delete [] residuals; delete [] resErrors;
668 delete [] chi2Array; delete [] chi2ArrayX;
669
670 m_nIterations=alignCache.m_iterationsOfLastFit+5;
672 ATH_MSG_DEBUG("exceeded max number of iterations");
673 resetIPar=false;
674 }
675 ATH_MSG_DEBUG("increasing m_nIterations to "<<m_nIterations<<" (not changing in fit yet)");
676 resetIPar=true;
677 ATH_MSG_INFO("fail align param cut, secPass "<<m_secPass);
678 if (m_secPass) {
680 }
681 Amg::VectorX emptyDerivatives;
682 return emptyDerivatives;
683 }
684
685 int imeas(0);
686 TCanvas* canv(nullptr);
687 std::vector<TGraph*> vecGraphs;
688 AlignTSOSCollection::const_iterator atsosItr=alignTrack->firstAtsos();
689 for (; atsosItr != alignTrack->lastAtsos(); ++atsosItr) {
690 if (!(*atsosItr)->isValid()) continue;
691 for (int idim=0;idim<(*atsosItr)->nResDim();idim++) {
692
693 double* gr_x = new double[NFITS];
694 double* gr_y = new double[NFITS]; // residuals only have float precision if determined from ESD
695 int ngoodfits=0;
696 for (int ifit=0;ifit<NFITS;ifit++) {
697 double residual=residuals[ifit][imeas];
698 double resError=resErrors[ifit][imeas];
699 if (residual>-999.) {
700 gr_x[ngoodfits] =chi2ArrayX[ifit];
701 gr_y[ngoodfits] =residual/resError;
702 ngoodfits++;
703 }
704 }
705
706 if (!m_doFits && ngoodfits==2) {
707 derivatives[imeas]=(residuals[1][imeas]-residuals[0][imeas])/(2.*shiftsize)*
708 resErrors[unshiftedTrackIndex][imeas];
709 }
710 else if (m_doFits && ngoodfits>3) {
711 TGraph* gr=new TGraph(ngoodfits,gr_x,gr_y);
712
714 gr->Fit("pol2","VF");
715 else
716 gr->Fit("pol2","QF");
717 TF1* fit=gr->GetFunction("pol2");
718
719 //double derivRatio=fit->GetParameter(2)/fit->GetParameter(1);
720 ATH_MSG_DEBUG("deriv["<<imeas<<"]="<<fit->GetParameter(1)<<" +/- "<<fit->GetParError(1)
721 <<", chi2="<<fit->GetChisquare());
722 derivatives[imeas]=fit->GetParameter(1)*resErrors[unshiftedTrackIndex][imeas]; // first derivative at x=0
723 derivativeErr[imeas]=fit->GetParError(1)*resErrors[unshiftedTrackIndex][imeas];
724
725
726 // plot residuals vs. chamber position
727 if (m_doResidualPlots) {
728 if (!canv) canv=new TCanvas("resPlots","resPlots");
729 canv->cd();
730 gr->SetMarkerStyle(20);
731 gr->Draw("AP");
732
733 gr->GetXaxis()->SetTitle("shift in chamber pos. from nominal (CLHEP::mm)");
734 gr->GetYaxis()->SetTitle("residual (CLHEP::mm)");
735
736 TPaveText* pave=new TPaveText(.4,.65,.97,.92,"NDC");
737 pave->SetFillColor(0);
738 pave->SetBorderSize(1);
739 std::stringstream measType; measType<<"meas type: ";
740 if ((*atsosItr)->measType()==TrackState::MDT) measType<<" MDT";
741 else if ((*atsosItr)->measType()==TrackState::TGC) measType<<" TGC";
742 else if ((*atsosItr)->measType()==TrackState::RPC) measType<<" RPC";
743 else measType<<" undefined";
744
745 pave->AddText(measType.str().c_str());
746
747 std::stringstream firstderivtxt,secndderivtxt,aptxt,chi2txt;
748 firstderivtxt<<fit->GetParameter(1)<<" +/- "<<fit->GetParError(1);
749 secndderivtxt<<fit->GetParameter(2)<<" +/- "<<fit->GetParError(2);
750 aptxt <<"alignPar "<<alignPar->paramType()<<", RIO in "<<(*atsosItr)->identify();
751 chi2txt<<"chi2="<<fit->GetChisquare();
752
753 pave->AddText(firstderivtxt.str().c_str());
754 pave->AddText(secndderivtxt.str().c_str());
755 pave->AddText(aptxt.str().c_str());
756 pave->AddText(chi2txt.str().c_str());
757 pave->Draw();
758
759 std::stringstream canvName;
760 canvName<<"resPlots_ap"<<alignPar->paramType()<<"_measType"
761 <<(*atsosItr)->measType()<<"_"<<imeas<<".eps";
762 canv->Print(canvName.str().c_str());
763 canv->Clear();
764
765 delete pave;
766 }
767 vecGraphs.push_back(gr);
768 }
769 else {
770 derivatives[imeas]=-999.;
771 derivativeErr[imeas]=-999.;
772 }
773
774 delete [] gr_y;
775 delete [] gr_x;
776
777 ++imeas;
778 }
779 }
780
781 // delete TGraphs and TCanvas
782 for (auto & vecGraph : vecGraphs)
783 delete vecGraph;
784 delete canv;
785
786 delete [] residuals;
787 delete [] resErrors;
788
789 // set chi2 v alignparam
790 for (int ifit=0;ifit<NFITS;ifit++) {
791 m_tmpChi2VAlignParamX[ipar]=chi2ArrayX;
792 m_tmpChi2VAlignParam [ipar]=chi2Array;
793 }
794
795 ATH_MSG_DEBUG("derivativeErr: "<<derivativeErr);
796 return derivatives;
797}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define gr
static Double_t sc
ServiceHandle< StoreGateSvc > & evtStore()
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
Gaudi::Property< bool > m_removeScatteringBeforeRefit
ToolHandle< IGlobalTrackFitter > m_fitter
double shiftSize(const AlignPar *alignPar) const
Gaudi::Property< int > m_maxIter
set minimum number of iterations for first track fits
Gaudi::Property< bool > m_doFits
ToolHandle< IAlignResidualCalculator > m_residualCalculator
ParticleHypothesis m_particleHypothesis
Gaudi::Property< bool > m_setMinIterations
reject track if exceed maximum number of iterations
Gaudi::Property< bool > m_doChi2VAlignParamMeasType
Gaudi::Property< bool > m_doResidualPlots
Gaudi::Property< double > m_trackAlignParamCut
fit track with AlignModules shifted up and down in each extreme, find the number of iterations fitter...
Gaudi::Property< bool > m_runOutlierRemoval
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
double chi2(TH1 *h0, TH1 *h1)
::StatusCode StatusCode
StatusCode definition for legacy code.
EventInfo_v1 EventInfo
Definition of the latest event info version.
int run(int argc, char *argv[])

◆ initialize()

StatusCode ShiftingDerivCalcTool::initialize ( )

Definition at line 54 of file ShiftingDerivCalcTool.cxx.

55 {
56
57 msg(MSG::DEBUG) << "in ShiftingDerivCalcTool initialize()"<<endmsg;
58 ATH_CHECK(m_trackFitterTool.retrieve());
61 ATH_CHECK(m_alignModuleTool.retrieve());
62
64 msg(MSG::INFO) << "ParticleNumber: " << m_particleNumber << endmsg;
65 msg(MSG::INFO) << "ParticleHypothesis: " << m_particleHypothesis << endmsg;
66
67
68 if(!m_doFits){
69 m_nFits = 2;
70 }
71
74
75 msg(MSG::INFO) << "doFits: " << m_doFits << endmsg;
76 msg(MSG::INFO) << "nFits: " << m_nFits << endmsg;
77
78 return StatusCode::SUCCESS;
79 }
#define ATH_CHECK
Evaluate an expression and check for errors.
Gaudi::Property< int > m_particleNumber
ToolHandle< IGlobalTrackFitter > m_trackFitterTool
Gaudi::Property< double > m_rotSize
ToolHandle< IGlobalTrackFitter > m_SLTrackFitterTool
Gaudi::Property< double > m_traSize
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ interfaceID()

const InterfaceID & IDerivCalcTool::interfaceID ( )
inlinestaticinherited

Retrieve interface ID.

Definition at line 84 of file IDerivCalcTool.h.

84 {
86 }
static const InterfaceID IID_TRKALIGNINTERFACES_IDerivCalcTool("IDerivCalcTool", 1, 0)

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ scanShifts()

bool ShiftingDerivCalcTool::scanShifts ( const AlignTrack * alignTrack,
const std::vector< AlignModule * > & alignModules )
private

Definition at line 100 of file ShiftingDerivCalcTool.cxx.

102 {
103 ATH_MSG_DEBUG("in scanShifts");
104
105 const Trk::Track* trackForRefit =
106 (m_removeScatteringBeforeRefit) ? alignTrack->trackWithoutScattering():
107 dynamic_cast<const Trk::Track*>(alignTrack);
108
109 // see whether straight track or not
110 m_fitter = alignTrack->isSLTrack() ?
112 ATH_MSG_DEBUG("refitting unshifted track with "<<m_fitter<<" (isSLTrack="
113 <<alignTrack->isSLTrack()<<")");
114
115 ATH_MSG_DEBUG("setting minNIterations to "<<m_nIterations);
116
117 // refit track
118
119 IGlobalTrackFitter::AlignmentCache alignCache;
120 alignCache.m_minIterations = m_nIterations;
121 const Track* refittedTrack = m_fitter->alignmentFit(alignCache, *trackForRefit,
124 if (!refittedTrack) {
125 msg(MSG::WARNING) << "initial track refit failed" << endmsg;
126 return false;
127 }
128 else
129 ATH_MSG_DEBUG("initial track refit successful");
130
131 m_nIterations = alignCache.m_iterationsOfLastFit;
133 ATH_MSG_DEBUG("exceeded maximum number of iterations");
134 return false;
135 }
136 ATH_MSG_DEBUG("initial nIterations: "<<m_nIterations);
137
138 // loop over AlignModules
139 for (std::vector<AlignModule*>::const_iterator moduleIt=alignModules.begin();
140 moduleIt!=alignModules.end(); ++moduleIt) {
141
142 // loop over AlignPar
143 DataVector<AlignPar>* alignPars=m_alignModuleTool->getAlignPars(*moduleIt);
144 for (DataVector<AlignPar>::iterator alignParIt=alignPars->begin();
145 alignParIt!=alignPars->end(); ++alignParIt) {
146
147 for (int ishift=0;ishift<2;ishift++) {
148
149 double shiftsize = shiftSize(*alignParIt);
150 if (ishift>0) shiftsize*=-1.;
151 m_alignModuleTool->shiftModule(*moduleIt,alignTrack,(**alignParIt).paramType(),shiftsize);
152 refittedTrack = (m_fitter->fit(Gaudi::Hive::currentContext(),
153 *trackForRefit,m_runOutlierRemoval,
154 m_particleHypothesis)).release();
155 m_alignModuleTool->restoreModule(*moduleIt);
156 if (!refittedTrack) {
157 msg(MSG::WARNING) << "track refit failed!"<<endmsg;
159 return false;
160 }
161
162 int nIter=alignCache.m_iterationsOfLastFit;
163 ATH_MSG_DEBUG("nIter: "<<nIter);
164 if (nIter>m_maxIter) {
165 ATH_MSG_DEBUG("exceeded maximum number of iterations");
167 return false;
168 }
169
170 if (nIter>m_nIterations) m_nIterations=nIter;
171 }
172 } // loop over AlignPar
173 } // loop over AlignModules
174
175 ATH_MSG_DEBUG("done with scanShifts, m_nIterations="<<m_nIterations);
176 return true;
177 }

◆ setChi2VAlignParam()

void Trk::ShiftingDerivCalcTool::setChi2VAlignParam ( const AlignTrack * alignTrack,
const AlignModule * module,
int nshifts = 0 )
protected

◆ setDerivatives()

bool ShiftingDerivCalcTool::setDerivatives ( AlignTrack * track)
virtual

sets derivatives of residuals w.r.t.

alignment parameters for hits on track.

Implements Trk::IDerivCalcTool.

Definition at line 262 of file ShiftingDerivCalcTool.cxx.

263{
264 ATH_MSG_DEBUG("in ShiftingDerivCalcTool setDerivatives");
266
267 // loop over AlignTSOSCollection,
268 // find modules that are in the AlignModuleList,
269 std::vector<AlignModule*> alignModules;
270 for (AlignTSOSCollection::iterator atsosItr=alignTrack->firstAtsos();
271 atsosItr != alignTrack->lastAtsos(); ++atsosItr) {
272
273 ATH_MSG_VERBOSE("getting module");
274 AlignModule* module=(*atsosItr)->module();
275 if (module)
276 ATH_MSG_VERBOSE("have ATSOS for module "<<module->identify());
277 else
278 ATH_MSG_VERBOSE("no module!");
279
280 if (!(*atsosItr)->isValid() || !module) continue;
281 if (find(alignModules.begin(),alignModules.end(),module) == alignModules.end())
282 alignModules.push_back(module);
283 }
284
285 // find perigee of best track fit and use as starting perigee for all fits
287 if (m_setMinIterations && !scanShifts(alignTrack, alignModules)) {
288 return false;
289 };
290
292
293 // set unshifted residuals (this is done in AlignTrackDresser but redone here with track refit)
294 if (!setUnshiftedResiduals(alignTrack)) {
295 ATH_MSG_WARNING("problem with refitting track!");
296 return false;
297 };
298
300
301 // Determine derivatives from shifting these modules
302 std::vector<AlignModuleDerivatives> * derivatives = new std::vector<AlignModuleDerivatives>;
303 std::vector<AlignModuleDerivatives> * derivativeErr = new std::vector<AlignModuleDerivatives>;
304 std::vector<std::pair<AlignModule*, std::vector<double> > > * actualSecondDerivatives =
305 new std::vector<std::pair<AlignModule*, std::vector<double> > >;
307 for (auto *alignModule : alignModules) {
308
309 ATH_MSG_DEBUG("finding derivatives for module "<<(*alignModule).identify());
310
311 std::vector<Amg::VectorX> deriv_vec;
312 std::vector<Amg::VectorX> derivErr_vec;
313 std::vector<double> actualsecderiv_vec;
314
315 // get alignPars and create arrays to store chi2 vs. align pars
316 DataVector<AlignPar>* alignPars=m_alignModuleTool->getAlignPars(alignModule);
317 const int nAlignPar = alignPars->size();
318 m_tmpChi2VAlignParam = new double*[nAlignPar];
319 m_tmpChi2VAlignParamX = new double*[nAlignPar];
323 m_tmpChi2VAlignParamMeasType[i] = new double*[nAlignPar];
324 }
325
326
327 // get derivatives and arrays of chi2 vs. align params
328 bool resetIPar=false;
329 std::vector<Amg::VectorX> tmpderiv_vec;
330 std::vector<Amg::VectorX> tmpderivErr_vec;
331 std::vector<double> tmpactualsecderiv_vec;
332 m_secPass=false;
333
334 // first attempt with normal number of fitter iterations
335 bool success=getAllDerivatives(
336 alignTrack, alignModule,
337 tmpderiv_vec,tmpderivErr_vec,tmpactualsecderiv_vec,
338 resetIPar);
339 if (!success){
340 delete derivatives;
341 delete derivativeErr;
342 delete actualSecondDerivatives;
343 return false;
344 }
345
347
348 if (resetIPar) {
349 // second attempt with increased number of fitter iterations
350 m_secPass=true;
351 success=getAllDerivatives(alignTrack,alignModule,
352 tmpderiv_vec,tmpderivErr_vec,tmpactualsecderiv_vec,
353 resetIPar);
354 }
355
356 if (!success){
357 delete derivatives;
358 delete derivativeErr;
359 delete actualSecondDerivatives;
360 return false;
361 }
362
364
365 if (resetIPar) {
366 // third and last attempt with number of fitter iterations set to maximum
368 success=getAllDerivatives(alignTrack,alignModule,
369 tmpderiv_vec,tmpderivErr_vec,tmpactualsecderiv_vec,
370 resetIPar);
371 }
372
373 if (!success){
374 delete derivatives;
375 delete derivativeErr;
376 delete actualSecondDerivatives;
377 return false;
378 }
379
380
382
383 if (success && !resetIPar) {
384 for (int i=0;i<(int)tmpderiv_vec.size();i++) {
385 deriv_vec.push_back(tmpderiv_vec[i]);
386 derivErr_vec.push_back(tmpderivErr_vec[i]);
387 actualsecderiv_vec.push_back(tmpactualsecderiv_vec[i]);
388 }
389 }
390 else{
391 delete derivatives;
392 delete derivativeErr;
393 delete actualSecondDerivatives;
394 return false;
395 }
396 // set the chi2 vs. align param arrays
397 ATH_MSG_DEBUG("setting chi2 vs. align param arrays");
400 (*alignModule).setChi2VAlignParamArray (m_tmpChi2VAlignParam);
401 (*alignModule).setChi2VAlignParamXArray(m_tmpChi2VAlignParamX);
402
403 // arrays for measurement types
405 ATH_MSG_DEBUG("pushing back for measType");
408 (*alignModule).setChi2VAlignParamArrayMeasType(i,m_tmpChi2VAlignParamMeasType[i]);
409 }
410 ATH_MSG_DEBUG("done setting arrays");
411
412 derivatives->push_back(make_pair(alignModule,deriv_vec));
413 derivativeErr->push_back(make_pair(alignModule,derivErr_vec));
414 actualSecondDerivatives->push_back(make_pair(alignModule,actualsecderiv_vec));
415 }
416
418
419 alignTrack->setDerivatives(derivatives);
420 alignTrack->setDerivativeErr(derivativeErr);
421 alignTrack->setActualSecondDerivatives(actualSecondDerivatives);
422
423 // restore unshifted residuals in AlignTSOS
424 setUnshiftedResiduals(alignTrack);
425
426 return true;
427}
size_type size() const noexcept
Returns the number of elements in the collection.
Gaudi::Property< int > m_minIter
flag to remove scattering before refitting track
bool getAllDerivatives(AlignTrack *alignTrack, const AlignModule *alignModule, std::vector< Amg::VectorX > &deriv_vec, std::vector< Amg::VectorX > &derivErr_vec, std::vector< double > &actualsecderiv_vec, bool &resetIPar)
bool scanShifts(const AlignTrack *alignTrack, const std::vector< AlignModule * > &alignModules)
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138

◆ setLogStream()

virtual void Trk::IDerivCalcTool::setLogStream ( std::ostream * os)
inlinevirtualinherited

sets the output stream for the logfile

Definition at line 71 of file IDerivCalcTool.h.

◆ setResidualCovMatrix()

bool ShiftingDerivCalcTool::setResidualCovMatrix ( AlignTrack * alignTrack) const
virtual

sets residual covariance matrix

Implements Trk::IDerivCalcTool.

Definition at line 814 of file ShiftingDerivCalcTool.cxx.

815{
816 Amg::MatrixX W(alignTrack->nAlignTSOSMeas(),alignTrack->nAlignTSOSMeas());
817
818 if (alignTrack->localErrorMatrixInv()) {
819 ATH_MSG_ERROR("Need to assign this matrix correctly: ShiftingDerivCalcTool.cxx:888");
820 W = *(alignTrack->localErrorMatrixInv());
821 //W.assign(*(alignTrack->localErrorMatrixInv()));
822 } else{
823 return false;
824 }
825 ATH_MSG_DEBUG("W: "<<W);
826
827 bool Wisvalid(true);
828 const double epsilon=1e-10;
829 for( int irow=0; irow<W.rows(); ++irow) {
830 Wisvalid = Wisvalid && W(irow,irow)>0;
831 if( !(W(irow,irow)>0) )
832 msg(MSG::WARNING) << "matrix invalid: " << W(irow,irow) << endmsg;
833
834 for(int icol=0; icol<=irow; ++icol) {
835
836 // this one must be true if everything else succeeded
837 double Wcorr = W(irow,icol)/sqrt(W(irow,irow)*W(icol,icol));
838 bool Wcorrisvalid = Wcorr+epsilon>=-1 && Wcorr-epsilon<=1;
839 Wisvalid = Wisvalid && Wcorrisvalid;
840 if( !Wcorrisvalid )
841 msg(MSG::WARNING) << "matrix corr invalid: " << Wcorr-1 << " " << Wcorr+1 << endmsg;
842 }
843 }
844
845 if (Wisvalid)
846 alignTrack->setWeightMatrix(new Amg::MatrixX(W));
847
848 alignTrack->setWeightMatrixFirstDeriv(new Amg::MatrixX(std::move(W)));
849
850 return true;
851}
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.

◆ setSolveOption()

void Trk::IDerivCalcTool::setSolveOption ( int solveOption)
inlineinherited

solving option (see enum above)

Definition at line 57 of file IDerivCalcTool.h.

57{ m_solveOption=solveOption; }

◆ setUnshiftedResiduals()

bool ShiftingDerivCalcTool::setUnshiftedResiduals ( AlignTrack * alignTrack)
protected

Definition at line 180 of file ShiftingDerivCalcTool.cxx.

181 {
182
183 // see whether straight track or not
184 m_fitter = alignTrack->isSLTrack() ?
186 ATH_MSG_DEBUG("refitting unshifted track with "<<m_fitter<<" (isSLTrack="
187 <<alignTrack->isSLTrack()<<")");
188
189 // refit track
190 ATH_MSG_DEBUG("\nsetting min number iterations to "<<m_nIterations);
191 IGlobalTrackFitter::AlignmentCache alignCache;
192 alignCache.m_minIterations = m_nIterations;
193
194 const Trk::Track* trackForRefit =
195 (m_removeScatteringBeforeRefit) ? alignTrack->trackWithoutScattering():
196 dynamic_cast<const Trk::Track*>(alignTrack);
197 if (!trackForRefit) {
198 ATH_MSG_ERROR("no track for refit!");
199 return false;
200 }
201
202 const Track* refittedTrack = m_fitter->alignmentFit( alignCache,
203 *trackForRefit,
206
207 if (!refittedTrack) {
208 ATH_MSG_WARNING( "initial track refit failed" );
209 return false;
210 }
211 else
212 ATH_MSG_DEBUG("initial track refit successful");
213
214 // dump local track chi2 for debugging
215 double localChi2=m_residualCalculator->setResiduals(alignTrack,refittedTrack);
216 msg()<<MSG::DEBUG<<"local Chi2(unshifted) in setChi2VAlignParam="<<localChi2<<endmsg;
217 m_unshiftedTrackChi2 = localChi2;
219 ATH_MSG_DEBUG("getting chi2 for measType "<<i);
221 }
222 ATH_MSG_DEBUG("done");
223
224 // create vector containing unshifted residuals and matrices containing errors
225 const int NMEAS=alignTrack->nAlignTSOSMeas();
226
227 // unshiftedResiduals owned by AlignTrack
229
230 // unshiftedResErrors owned by ShiftingDerivCalcTool
233
234 // loop over atsos and determine residuals and errors
235 int imeas=0;
236 AlignTSOSCollection::const_iterator atsosItr=alignTrack->firstAtsos();
237 for (; atsosItr != alignTrack->lastAtsos(); ++atsosItr) {
238 if (!(**atsosItr).isValid()) continue;
239 for (std::vector<Residual>::const_iterator itRes=(**atsosItr).firstResidual();
240 itRes!=(**atsosItr).lastResidual();++itRes,++imeas) {
241 double residual = itRes->residual();
242 double errSq = itRes->errSq();
243 (*m_unshiftedResiduals)[imeas]=residual;
244 (*m_unshiftedResErrors)[imeas]=std::sqrt(errSq);
245 //ATH_MSG_DEBUG("weight: "<<1./errSq<<", unshiftedRes["<<imeas<<"]="
246 // <<(*m_unshiftedResiduals)[imeas]
247 // <<", resNorm="<<itRes->residualNorm());
248 }
249 }
250 if (imeas!=NMEAS) {
251 msg(MSG::ERROR)<<"problem with nmeas, imeas="<<imeas<<", NMEAS="<<NMEAS<<endmsg;
252 throw std::runtime_error("Error in ShiftingDerivCalcTool::setUnshiftedResiduals");
253 }
254 alignTrack->setResidualVector(m_unshiftedResiduals);
255
256 delete refittedTrack; refittedTrack=nullptr;
257
258 return true;
259 }

◆ shiftSize()

double ShiftingDerivCalcTool::shiftSize ( const AlignPar * alignPar) const
protected

Definition at line 800 of file ShiftingDerivCalcTool.cxx.

800 {
801 bool rotation =
802 alignPar->paramType() == AlignModule::RotX ||
803 alignPar->paramType() == AlignModule::RotY ||
804 alignPar->paramType() == AlignModule::RotZ;
805
806 double shift = rotation ? m_rotSize : m_traSize;
807
808 //ok... this is kind of ugly.
809 double sigma=alignPar->sigma();
810 return shift * sigma;
811}

◆ showStatistics()

void Trk::ShiftingDerivCalcTool::showStatistics ( )
inlinevirtual

write statistics to log file

Implements Trk::IDerivCalcTool.

Definition at line 59 of file ShiftingDerivCalcTool.h.

59{}

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_alignModuleTool

ToolHandle<IAlignModuleTool> Trk::ShiftingDerivCalcTool::m_alignModuleTool {this, "AlignModuleTool", "Trk::AlignModuleTool/AlignModuleTool"}
private

Definition at line 106 of file ShiftingDerivCalcTool.h.

107{this, "AlignModuleTool", "Trk::AlignModuleTool/AlignModuleTool"};

◆ m_chi2VAlignParamVec

std::vector<double**> Trk::ShiftingDerivCalcTool::m_chi2VAlignParamVec
private

track chi2[idof][ichambershift]

Definition at line 131 of file ShiftingDerivCalcTool.h.

◆ m_chi2VAlignParamVecMeasType

std::vector<double***> Trk::ShiftingDerivCalcTool::m_chi2VAlignParamVecMeasType
private

track chi2[idof][imeastype][ichambershift]

Definition at line 140 of file ShiftingDerivCalcTool.h.

◆ m_chi2VAlignParamXVec

std::vector<double**> Trk::ShiftingDerivCalcTool::m_chi2VAlignParamXVec
private

chamber shift[idof][ichambershift]

Definition at line 132 of file ShiftingDerivCalcTool.h.

◆ m_derivative_map

DerivativeMap Trk::ShiftingDerivCalcTool::m_derivative_map
private

Definition at line 118 of file ShiftingDerivCalcTool.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_doChi2VAlignParamMeasType

Gaudi::Property<bool> Trk::ShiftingDerivCalcTool::m_doChi2VAlignParamMeasType {this, "doChi2VChamberShiftsMeasType", false}
private

Definition at line 122 of file ShiftingDerivCalcTool.h.

123{this, "doChi2VChamberShiftsMeasType", false};

◆ m_doFits

Gaudi::Property<bool> Trk::ShiftingDerivCalcTool::m_doFits {this, "doResidualFits", true}
private

Definition at line 120 of file ShiftingDerivCalcTool.h.

120{this, "doResidualFits", true};

◆ m_doResidualPlots

Gaudi::Property<bool> Trk::ShiftingDerivCalcTool::m_doResidualPlots {this, "doResidualPlots", false}
private

Definition at line 124 of file ShiftingDerivCalcTool.h.

124{this, "doResidualPlots", false};

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_fitter

ToolHandle<IGlobalTrackFitter> Trk::ShiftingDerivCalcTool::m_fitter
private

Definition at line 102 of file ShiftingDerivCalcTool.h.

◆ m_logStream

std::ostream* Trk::IDerivCalcTool::m_logStream = nullptr
protectedinherited

logfile output stream

Definition at line 76 of file IDerivCalcTool.h.

◆ m_maxIter

Gaudi::Property<int> Trk::ShiftingDerivCalcTool::m_maxIter {this, "MaxIterations", 50}
private

set minimum number of iterations for first track fits

Definition at line 152 of file ShiftingDerivCalcTool.h.

152{this, "MaxIterations", 50};

◆ m_minIter

Gaudi::Property<int> Trk::ShiftingDerivCalcTool::m_minIter {this, "MinIterations", 10}
private

flag to remove scattering before refitting track

Definition at line 155 of file ShiftingDerivCalcTool.h.

155{this, "MinIterations", 10};

◆ m_nFits

Gaudi::Property<int> Trk::ShiftingDerivCalcTool::m_nFits {this, "NumberOfShifts", 5}
private

Definition at line 121 of file ShiftingDerivCalcTool.h.

121{this, "NumberOfShifts", 5};

◆ m_nIterations

int Trk::ShiftingDerivCalcTool::m_nIterations = 0
private

Definition at line 125 of file ShiftingDerivCalcTool.h.

◆ m_ntracksFailAlignParamCut

int Trk::ShiftingDerivCalcTool::m_ntracksFailAlignParamCut = 0
private

Definition at line 170 of file ShiftingDerivCalcTool.h.

◆ m_ntracksFailFinalAttempt

int Trk::ShiftingDerivCalcTool::m_ntracksFailFinalAttempt = 0
private

Definition at line 171 of file ShiftingDerivCalcTool.h.

◆ m_ntracksFailMaxIter

int Trk::ShiftingDerivCalcTool::m_ntracksFailMaxIter = 0
private

Definition at line 168 of file ShiftingDerivCalcTool.h.

◆ m_ntracksFailTrackRefit

int Trk::ShiftingDerivCalcTool::m_ntracksFailTrackRefit = 0
private

Definition at line 169 of file ShiftingDerivCalcTool.h.

◆ m_ntracksPassDerivatives

int Trk::ShiftingDerivCalcTool::m_ntracksPassDerivatives = 0
private

number tracks pass setting derivatives

Definition at line 164 of file ShiftingDerivCalcTool.h.

◆ m_ntracksPassGetDeriv

int Trk::ShiftingDerivCalcTool::m_ntracksPassGetDeriv = 0
private

number tracks pass getting derivatives

Definition at line 165 of file ShiftingDerivCalcTool.h.

◆ m_ntracksPassGetDerivLastPass

int Trk::ShiftingDerivCalcTool::m_ntracksPassGetDerivLastPass = 0
private

number tracks pass 2nd pass of getting derivatives

Definition at line 167 of file ShiftingDerivCalcTool.h.

◆ m_ntracksPassGetDerivSecPass

int Trk::ShiftingDerivCalcTool::m_ntracksPassGetDerivSecPass = 0
private

number tracks pass 2nd pass of getting derivatives

Definition at line 166 of file ShiftingDerivCalcTool.h.

◆ m_ntracksPassInitScan

int Trk::ShiftingDerivCalcTool::m_ntracksPassInitScan = 0
private

number tracks pass initial scan

Definition at line 162 of file ShiftingDerivCalcTool.h.

◆ m_ntracksPassSetUnshiftedRes

int Trk::ShiftingDerivCalcTool::m_ntracksPassSetUnshiftedRes = 0
private

number tracks pass setting unshifted residuals

Definition at line 163 of file ShiftingDerivCalcTool.h.

◆ m_ntracksProcessed

int Trk::ShiftingDerivCalcTool::m_ntracksProcessed = 0
private

number tracks processed

Definition at line 161 of file ShiftingDerivCalcTool.h.

◆ m_particleHypothesis

ParticleHypothesis Trk::ShiftingDerivCalcTool::m_particleHypothesis = Trk::muon
private

Definition at line 114 of file ShiftingDerivCalcTool.h.

◆ m_particleNumber

Gaudi::Property<int> Trk::ShiftingDerivCalcTool::m_particleNumber {this, "ParticleNumber", 2}
private

Definition at line 116 of file ShiftingDerivCalcTool.h.

116{this, "ParticleNumber", 2};

◆ m_removeScatteringBeforeRefit

Gaudi::Property<bool> Trk::ShiftingDerivCalcTool::m_removeScatteringBeforeRefit {this, "RemoveScatteringBeforeRefit", false}
private

Definition at line 158 of file ShiftingDerivCalcTool.h.

159{this, "RemoveScatteringBeforeRefit", false};

◆ m_residualCalculator

ToolHandle<IAlignResidualCalculator> Trk::ShiftingDerivCalcTool::m_residualCalculator {this, "ResidualCalculator", "Trk::AlignResidualCalculator/ResidualCalculator"}
private

Definition at line 104 of file ShiftingDerivCalcTool.h.

105{this, "ResidualCalculator", "Trk::AlignResidualCalculator/ResidualCalculator"};

◆ m_rotSize

Gaudi::Property<double> Trk::ShiftingDerivCalcTool::m_rotSize {this, "RotationSize", .1}
private

Definition at line 110 of file ShiftingDerivCalcTool.h.

110{this, "RotationSize", .1};

◆ m_runOutlierRemoval

Gaudi::Property<bool> Trk::ShiftingDerivCalcTool::m_runOutlierRemoval {this, "RunOutlierRemoval", false}
private

Definition at line 112 of file ShiftingDerivCalcTool.h.

113{this, "RunOutlierRemoval", false};

◆ m_secPass

bool Trk::ShiftingDerivCalcTool::m_secPass {}
private

Definition at line 173 of file ShiftingDerivCalcTool.h.

173{};

◆ m_setMinIterations

Gaudi::Property<bool> Trk::ShiftingDerivCalcTool::m_setMinIterations {this, "SetMinIterations", false}
private

reject track if exceed maximum number of iterations

Definition at line 149 of file ShiftingDerivCalcTool.h.

149{this, "SetMinIterations", false};

◆ m_SLTrackFitterTool

ToolHandle<IGlobalTrackFitter> Trk::ShiftingDerivCalcTool::m_SLTrackFitterTool {this, "SLTrackFitterTool", "Trk::GlobalChi2Fitter/MCTBSLFitter"}
private

Definition at line 100 of file ShiftingDerivCalcTool.h.

101{this, "SLTrackFitterTool", "Trk::GlobalChi2Fitter/MCTBSLFitter"};

◆ m_solveOption

int Trk::IDerivCalcTool::m_solveOption = 0
privateinherited

Definition at line 80 of file IDerivCalcTool.h.

◆ m_tmpChi2VAlignParam

double** Trk::ShiftingDerivCalcTool::m_tmpChi2VAlignParam = nullptr
private

Definition at line 134 of file ShiftingDerivCalcTool.h.

◆ m_tmpChi2VAlignParamMeasType

double*** Trk::ShiftingDerivCalcTool::m_tmpChi2VAlignParamMeasType = nullptr
private

Definition at line 136 of file ShiftingDerivCalcTool.h.

◆ m_tmpChi2VAlignParamX

double** Trk::ShiftingDerivCalcTool::m_tmpChi2VAlignParamX = nullptr
private

Definition at line 135 of file ShiftingDerivCalcTool.h.

◆ m_trackAlignParamCut

Gaudi::Property<double> Trk::ShiftingDerivCalcTool::m_trackAlignParamCut {this, "TrackAlignParamCut", 1e6}
private

fit track with AlignModules shifted up and down in each extreme, find the number of iterations fitter uses to converge.

Set this number for all subsequent track refits.

Definition at line 146 of file ShiftingDerivCalcTool.h.

146{this, "TrackAlignParamCut", 1e6};

◆ m_trackFitterTool

ToolHandle<IGlobalTrackFitter> Trk::ShiftingDerivCalcTool::m_trackFitterTool {this, "TrackFitterTool", "Trk::GlobalChi2Fitter/MCTBFitter"}
private

Definition at line 98 of file ShiftingDerivCalcTool.h.

99{this, "TrackFitterTool", "Trk::GlobalChi2Fitter/MCTBFitter"};

◆ m_traSize

Gaudi::Property<double> Trk::ShiftingDerivCalcTool::m_traSize {this, "TranslationSize", .1}
private

Definition at line 109 of file ShiftingDerivCalcTool.h.

109{this, "TranslationSize", .1};

◆ m_unshiftedResErrors

Amg::VectorX* Trk::ShiftingDerivCalcTool::m_unshiftedResErrors = nullptr
private

Definition at line 128 of file ShiftingDerivCalcTool.h.

◆ m_unshiftedResiduals

Amg::VectorX* Trk::ShiftingDerivCalcTool::m_unshiftedResiduals = nullptr
private

Definition at line 127 of file ShiftingDerivCalcTool.h.

◆ m_unshiftedTrackChi2

double Trk::ShiftingDerivCalcTool::m_unshiftedTrackChi2 {}
private

Definition at line 142 of file ShiftingDerivCalcTool.h.

142{};

◆ m_unshiftedTrackChi2MeasType

std::unique_ptr<double[]> Trk::ShiftingDerivCalcTool::m_unshiftedTrackChi2MeasType
private

cut on value of track alignment parameter, determined from fit of chi2 vs.

align parameters to a quadratic

Definition at line 143 of file ShiftingDerivCalcTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: