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

◆ 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 859 of file ShiftingDerivCalcTool.cxx.

860{
861 for (int i=0;i<(int)m_chi2VAlignParamVec.size();i++) {
862 delete [] m_chi2VAlignParamVec[i]; m_chi2VAlignParamVec[i]=nullptr;
863 delete [] m_chi2VAlignParamXVec[i]; m_chi2VAlignParamXVec[i]=nullptr;
864 }
865 m_chi2VAlignParamVec.clear();
866 m_chi2VAlignParamXVec.clear();
867
868 for (auto & i : m_chi2VAlignParamVecMeasType) {
869 delete [] i; i=nullptr;
870 }
872}
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 875 of file ShiftingDerivCalcTool.cxx.

882{
883 resetIPar=false;
884
885 deriv_vec.clear();
886 derivErr_vec.clear();
887 actualsecderiv_vec.clear();
888
889 setUnshiftedResiduals(alignTrack); // this will set the min number of iterations to the new value
890
891 int ipar(0);
892 DataVector<AlignPar>* alignPars=m_alignModuleTool->getAlignPars(alignModule);
893 for (DataVector<AlignPar>::iterator it=alignPars->begin(); it!=alignPars->end(); ++it,ipar++) {
894 ATH_MSG_DEBUG("ipar: "<<ipar);
895 Amg::VectorX derivErr(alignTrack->nAlignTSOSMeas());
896 double actualSecondDeriv(0.);
897 const Amg::VectorX vec=getDerivatives(alignTrack,ipar,*it,derivErr,resetIPar,actualSecondDeriv);
898 ATH_MSG_DEBUG("vec size: "<<vec.rows());
899
900 ATH_MSG_DEBUG("resetIPar="<<resetIPar);
901 if (resetIPar) continue; // continue with derivatives to find max iteration
902
903 if (vec.rows()<1) return false; // derivatives won't be set for alignTrack because it's a bad track
904
905 deriv_vec.push_back(vec);
906 derivErr_vec.push_back(derivErr);
907 actualsecderiv_vec.push_back(actualSecondDeriv);
908
909 for (int i=0;i<m_nFits;i++) {
910 ATH_MSG_DEBUG("m_tmpChi2VAlignParam["<<ipar<<"]["
911 <<i<<"]="<<m_tmpChi2VAlignParam[ipar][i]);
912 }
913 }
914
915 return true;
916}
#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 433 of file ShiftingDerivCalcTool.cxx.

439{
440 const EventContext& ctx = Gaudi::Hive::currentContext();
441
442 const Trk::Track* trackForRefit =
443 (m_removeScatteringBeforeRefit) ? alignTrack->trackWithoutScattering():
444 dynamic_cast<const Trk::Track*>(alignTrack);
445
446 ATH_MSG_DEBUG("m_nIterations: "<<m_nIterations);
447
448 // gets derivatives of residuals w.r.t. a specific alignment parameter given by alignPar
449 if (!m_fitter)
450 ATH_MSG_ERROR("set m_fitter before calling getDerivatives (by calling setUnshiftedResiduals)");
451
452 AlignModule* module=alignPar->alignModule();
453
454 // set derivatives for 2 shifts up and 2 shifts down
455 const int NFITS = m_nFits;
456 const int NMEAS = alignTrack->nAlignTSOSMeas();
457 module->setNChamberShifts(m_nFits);
458
459 ATH_MSG_DEBUG("NMEAS="<<NMEAS);
460 double** residuals=new double*[NFITS];
461 double** resErrors=new double*[NFITS];
462 double* chi2Array =new double[NFITS];
463 double* chi2ArrayX=new double[NFITS];
464
467 m_tmpChi2VAlignParamMeasType[i][ipar] =new double[NFITS];
468 }
469
470 for (int ifit=0;ifit<NFITS;ifit++) {
471 residuals[ifit]=new double[NMEAS];
472 resErrors[ifit]=new double[NMEAS];
473 }
474
475 // set the values for the unshifted track
476 const int unshiftedTrackIndex = m_doFits ? (m_nFits-1)/2 : 1;
477 chi2Array [unshiftedTrackIndex] = m_unshiftedTrackChi2;
478 ATH_MSG_DEBUG("chi2Array["<<unshiftedTrackIndex<<"]="<<chi2Array[unshiftedTrackIndex]);
479 chi2ArrayX[unshiftedTrackIndex] = 0.;
482 m_tmpChi2VAlignParamMeasType[i][ipar][unshiftedTrackIndex]=
484 ATH_MSG_DEBUG("chi2ArrayMeasType["<<i<<"]["<<unshiftedTrackIndex<<"]="<<m_unshiftedTrackChi2MeasType[i]);
485 }
486 }
487
488
489 // get shift size
490 double shiftsize=shiftSize(alignPar);
491
492 IGlobalTrackFitter::AlignmentCache alignCache;
493
494
495 ATH_MSG_VERBOSE("doing refits");
496 for (int ifit=0;ifit<NFITS;ifit++) {
497
498 ATH_MSG_VERBOSE("ifit="<<ifit);
499 int jfit=ifit;
500 if (ifit>unshiftedTrackIndex) {
501 jfit=NFITS-ifit+unshiftedTrackIndex;
502 }
503 if (m_doFits && ifit==unshiftedTrackIndex) {
504 for (int i=0;i<(int)m_unshiftedResiduals->rows();i++) {
505 residuals[ifit][i]=(*m_unshiftedResiduals)[i];
506 resErrors[ifit][i]=(*m_unshiftedResErrors)[i];
507 }
508 // change back in case it got changed on the other side of zero
509 shiftsize=shiftSize(alignPar);
510 continue;
511 }
512
513 // shift module and fit track
514 double currentshift = 0.;
515 if(m_doFits)
516 currentshift = shiftsize * (double)(jfit-unshiftedTrackIndex);
517 else
518 currentshift = (ifit==0) ? -1.*shiftsize : shiftsize;
519
520 ATH_MSG_DEBUG("current shift="<<currentshift<<" in getDerivatives");
521
522 m_alignModuleTool->shiftModule(module,alignTrack,
523 alignPar->paramType(),currentshift);
524
525
526 ATH_MSG_VERBOSE("fitting after shift");
527 const Track* refittedTrack=m_fitter->alignmentFit(ctx, alignCache,
528 *trackForRefit,
530 if (m_setMinIterations && alignCache.m_iterationsOfLastFit>m_nIterations) {
531 m_nIterations=alignCache.m_iterationsOfLastFit;
533 ATH_MSG_DEBUG("exceeded max number of iterations");
534 m_alignModuleTool->restoreModule(module);
535 resetIPar=false;
536 ATH_MSG_DEBUG("resetIPar set to false");
537 delete [] residuals; delete [] resErrors;
538 delete [] chi2Array; delete [] chi2ArrayX;
539 ATH_MSG_DEBUG("fail max iter");
541 Amg::VectorX derivatives(1);
542 return derivatives;
543 }
544 ATH_MSG_DEBUG("increasing m_nIterations to "<<m_nIterations<<" (not changing in fit yet)");
545 resetIPar=true;
546 ATH_MSG_DEBUG("resetIPar set to true");
547 }
548
549 // if resetIPar refit the rest of the tracks, but don't do anything with them until next pass
550 if (resetIPar) {
551 m_alignModuleTool->restoreModule(module);
552 continue;
553 }
554
555 if (!refittedTrack) {
556 msg(MSG::WARNING) << "track refit failed for jfit "<<jfit <<endmsg;
557 delete [] residuals; delete [] resErrors;
558 delete [] chi2Array; delete [] chi2ArrayX;
559 m_alignModuleTool->restoreModule(module);
560 if (!resetIPar || m_secPass) {
562 }
563 ATH_MSG_DEBUG("fail track refit, resetIPar "<<resetIPar<<", secPass "<<m_secPass);
564 Amg::VectorX derivatives(1);
565 return derivatives;
566 }
567 else
568 ATH_MSG_VERBOSE("track refit successful");
569
570 double chi2=refittedTrack->fitQuality()->chiSquared();
571
572 ATH_MSG_VERBOSE("jfit = "<<jfit);
573 double localChi2=m_residualCalculator->setResiduals(alignTrack,refittedTrack);
574 ATH_MSG_DEBUG("localChi2/fittedChi2="<<localChi2<<"/"<<chi2);
575
576 chi2ArrayX[jfit]= shiftsize * (double)(jfit-unshiftedTrackIndex);// / module->sigma(idof);
577 chi2Array[jfit]=localChi2;
578 ATH_MSG_DEBUG("chi2Array["<<jfit<<"]="<<chi2Array[jfit]);
581 m_tmpChi2VAlignParamMeasType[i][ipar][jfit]= m_residualCalculator->chi2ForMeasType(i);
582 ATH_MSG_DEBUG("chi2ArrayMeasType["<<i<<"]["<<jfit<<"]="
583 <<m_tmpChi2VAlignParamMeasType[i][ipar][jfit]);
584 }
585 }
586
587 ATH_MSG_DEBUG("positions["<<jfit<<"]="<<chi2ArrayX[jfit]);
588
589 int imeas(0);
590 AlignTSOSCollection::const_iterator atsosItr=alignTrack->firstAtsos();
591 for (; atsosItr != alignTrack->lastAtsos(); ++atsosItr) {
592 if (!(*atsosItr)->isValid()) continue;
593 for (std::vector<Residual>::const_iterator itRes=(**atsosItr).firstResidual();
594 itRes!=(**atsosItr).lastResidual();++itRes,++imeas) {
595
596 if (refittedTrack) {
597 residuals[jfit][imeas]=itRes->residual();
598 resErrors[jfit][imeas]=std::sqrt(itRes->errSq());
599 }
600 else {
601 residuals[jfit][imeas]=resErrors[jfit][imeas]=0.;
602 }
603 ATH_MSG_DEBUG("residuals["<<jfit<<"]["<<imeas<<"]="<<residuals[jfit][imeas]);
604 ATH_MSG_DEBUG("resErrors["<<jfit<<"]["<<imeas<<"]="<<resErrors[jfit][imeas]);
605 }
606 }
607
608 delete refittedTrack; refittedTrack=nullptr;
609 ATH_MSG_VERBOSE("calling restoreModule");
610 m_alignModuleTool->restoreModule(module);
611 } // NFITS
612
613 int iimeas(0);
614 AlignTSOSCollection::const_iterator aatsosItr=alignTrack->firstAtsos();
615 for (; aatsosItr != alignTrack->lastAtsos(); ++aatsosItr) {
616 if (!(*aatsosItr)->isValid()) continue;
617 for (std::vector<Residual>::const_iterator itRes=(**aatsosItr).firstResidual();
618 itRes!=(**aatsosItr).lastResidual();++itRes,++iimeas) {
619 for (int ifit=0;ifit<NFITS;ifit++) {
620 ATH_MSG_DEBUG("["<<ifit<<"]["<<iimeas<<"] res="<<residuals[ifit][iimeas]<<
621 ", resErr="<<resErrors[ifit][iimeas]);
622 }
623 }
624 }
625
626 if (resetIPar) {
627 //resetIPar=false;
628 delete [] residuals; delete [] resErrors;
629 delete [] chi2Array; delete [] chi2ArrayX;
630 if (m_secPass) ATH_MSG_WARNING("failed second pass!");
631 ATH_MSG_DEBUG("returning to reset IPar");
632 Amg::VectorX derivatives;
633 return derivatives;
634 }
635
636 // check chi2 vs. chamber pos to see if discontinuous
637 TGraph* gr = new TGraph(m_nFits,chi2ArrayX,chi2Array);
638 gr->Fit("pol2","QF");
639 TF1* fit=gr->GetFunction("pol2");
640 double chi2 =fit->GetChisquare()/double(m_nFits-3);
641 double slope=fit->GetParameter(1);
642 actualSecondDeriv=fit->GetParameter(2);
643 delete gr;
644
645 ATH_MSG_DEBUG("discontinuity check: chi2="<<chi2);
646 alignTrack->setTrackAlignParamQuality(alignPar->paramType(),chi2);
647
648 // EventInfo
649 if (chi2>1.e-6 || std::fabs(slope)<1.e-10) {
650 const xAOD::EventInfo* eventInfo;
651 StatusCode sc=evtStore()->retrieve(eventInfo);
652 if (sc.isFailure())
653 ATH_MSG_ERROR("Couldn't retrieve event info");
654 int run=eventInfo->runNumber();
655 int evt=eventInfo->eventNumber();
656 ATH_MSG_DEBUG("discontinuity check: chi2="<<chi2<<", run/evt "<<run<<"/"<<evt);
657 }
658
659 //reset in case it got changed somewhere
660 shiftsize = shiftSize(alignPar);
661
662 //-----------------------------------------//
663 //-- get derivatives from residuals --//
664 //-----------------------------------------//
665 ATH_MSG_VERBOSE("calculating residuals");
666 Amg::VectorX derivatives(alignTrack->nAlignTSOSMeas(),0);
667 ATH_MSG_DEBUG("created derivatives with "<<derivatives.rows()<<" rows");
668
669 // if bad fit or first derivative close to zero, replace derivatives with zeros
670 if (chi2>m_trackAlignParamCut) {// || std::fabs(slope)<1.e-10 ) {
671 ATH_MSG_DEBUG("chi2/"<<m_nFits-3<<"="<<chi2);
672 delete [] residuals; delete [] resErrors;
673 delete [] chi2Array; delete [] chi2ArrayX;
674
675 m_nIterations=alignCache.m_iterationsOfLastFit+5;
677 ATH_MSG_DEBUG("exceeded max number of iterations");
678 resetIPar=false;
679 }
680 ATH_MSG_DEBUG("increasing m_nIterations to "<<m_nIterations<<" (not changing in fit yet)");
681 resetIPar=true;
682 ATH_MSG_INFO("fail align param cut, secPass "<<m_secPass);
683 if (m_secPass) {
685 }
686 Amg::VectorX emptyDerivatives;
687 return emptyDerivatives;
688 }
689
690 int imeas(0);
691 TCanvas* canv(nullptr);
692 std::vector<TGraph*> vecGraphs;
693 AlignTSOSCollection::const_iterator atsosItr=alignTrack->firstAtsos();
694 for (; atsosItr != alignTrack->lastAtsos(); ++atsosItr) {
695 if (!(*atsosItr)->isValid()) continue;
696 for (int idim=0;idim<(*atsosItr)->nResDim();idim++) {
697
698 double* gr_x = new double[NFITS];
699 double* gr_y = new double[NFITS]; // residuals only have float precision if determined from ESD
700 int ngoodfits=0;
701 for (int ifit=0;ifit<NFITS;ifit++) {
702 double residual=residuals[ifit][imeas];
703 double resError=resErrors[ifit][imeas];
704 if (residual>-999.) {
705 gr_x[ngoodfits] =chi2ArrayX[ifit];
706 gr_y[ngoodfits] =residual/resError;
707 ngoodfits++;
708 }
709 }
710
711 if (!m_doFits && ngoodfits==2) {
712 derivatives[imeas]=(residuals[1][imeas]-residuals[0][imeas])/(2.*shiftsize)*
713 resErrors[unshiftedTrackIndex][imeas];
714 }
715 else if (m_doFits && ngoodfits>3) {
716 TGraph* gr=new TGraph(ngoodfits,gr_x,gr_y);
717
719 gr->Fit("pol2","VF");
720 else
721 gr->Fit("pol2","QF");
722 TF1* fit=gr->GetFunction("pol2");
723
724 //double derivRatio=fit->GetParameter(2)/fit->GetParameter(1);
725 ATH_MSG_DEBUG("deriv["<<imeas<<"]="<<fit->GetParameter(1)<<" +/- "<<fit->GetParError(1)
726 <<", chi2="<<fit->GetChisquare());
727 derivatives[imeas]=fit->GetParameter(1)*resErrors[unshiftedTrackIndex][imeas]; // first derivative at x=0
728 derivativeErr[imeas]=fit->GetParError(1)*resErrors[unshiftedTrackIndex][imeas];
729
730
731 // plot residuals vs. chamber position
732 if (m_doResidualPlots) {
733 if (!canv) canv=new TCanvas("resPlots","resPlots");
734 canv->cd();
735 gr->SetMarkerStyle(20);
736 gr->Draw("AP");
737
738 gr->GetXaxis()->SetTitle("shift in chamber pos. from nominal (CLHEP::mm)");
739 gr->GetYaxis()->SetTitle("residual (CLHEP::mm)");
740
741 TPaveText* pave=new TPaveText(.4,.65,.97,.92,"NDC");
742 pave->SetFillColor(0);
743 pave->SetBorderSize(1);
744 std::stringstream measType; measType<<"meas type: ";
745 if ((*atsosItr)->measType()==TrackState::MDT) measType<<" MDT";
746 else if ((*atsosItr)->measType()==TrackState::TGC) measType<<" TGC";
747 else if ((*atsosItr)->measType()==TrackState::RPC) measType<<" RPC";
748 else measType<<" undefined";
749
750 pave->AddText(measType.str().c_str());
751
752 std::stringstream firstderivtxt,secndderivtxt,aptxt,chi2txt;
753 firstderivtxt<<fit->GetParameter(1)<<" +/- "<<fit->GetParError(1);
754 secndderivtxt<<fit->GetParameter(2)<<" +/- "<<fit->GetParError(2);
755 aptxt <<"alignPar "<<alignPar->paramType()<<", RIO in "<<(*atsosItr)->identify();
756 chi2txt<<"chi2="<<fit->GetChisquare();
757
758 pave->AddText(firstderivtxt.str().c_str());
759 pave->AddText(secndderivtxt.str().c_str());
760 pave->AddText(aptxt.str().c_str());
761 pave->AddText(chi2txt.str().c_str());
762 pave->Draw();
763
764 std::stringstream canvName;
765 canvName<<"resPlots_ap"<<alignPar->paramType()<<"_measType"
766 <<(*atsosItr)->measType()<<"_"<<imeas<<".eps";
767 canv->Print(canvName.str().c_str());
768 canv->Clear();
769
770 delete pave;
771 }
772 vecGraphs.push_back(gr);
773 }
774 else {
775 derivatives[imeas]=-999.;
776 derivativeErr[imeas]=-999.;
777 }
778
779 delete [] gr_y;
780 delete [] gr_x;
781
782 ++imeas;
783 }
784 }
785
786 // delete TGraphs and TCanvas
787 for (auto & vecGraph : vecGraphs)
788 delete vecGraph;
789 delete canv;
790
791 delete [] residuals;
792 delete [] resErrors;
793
794 // set chi2 v alignparam
795 for (int ifit=0;ifit<NFITS;ifit++) {
796 m_tmpChi2VAlignParamX[ipar]=chi2ArrayX;
797 m_tmpChi2VAlignParam [ipar]=chi2Array;
798 }
799
800 ATH_MSG_DEBUG("derivativeErr: "<<derivativeErr);
801 return derivatives;
802}
#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 EventContext& ctx = Gaudi::Hive::currentContext();
106
107 const Trk::Track* trackForRefit =
108 (m_removeScatteringBeforeRefit) ? alignTrack->trackWithoutScattering():
109 dynamic_cast<const Trk::Track*>(alignTrack);
110
111 // see whether straight track or not
112 m_fitter = alignTrack->isSLTrack() ?
114 ATH_MSG_DEBUG("refitting unshifted track with "<<m_fitter<<" (isSLTrack="
115 <<alignTrack->isSLTrack()<<")");
116
117 ATH_MSG_DEBUG("setting minNIterations to "<<m_nIterations);
118
119 // refit track
120
121 IGlobalTrackFitter::AlignmentCache alignCache;
122 alignCache.m_minIterations = m_nIterations;
123 const Track* refittedTrack = m_fitter->alignmentFit(ctx, alignCache, *trackForRefit,
126 if (!refittedTrack) {
127 msg(MSG::WARNING) << "initial track refit failed" << endmsg;
128 return false;
129 }
130 else
131 ATH_MSG_DEBUG("initial track refit successful");
132
133 m_nIterations = alignCache.m_iterationsOfLastFit;
135 ATH_MSG_DEBUG("exceeded maximum number of iterations");
136 return false;
137 }
138 ATH_MSG_DEBUG("initial nIterations: "<<m_nIterations);
139
140 // loop over AlignModules
141 for (std::vector<AlignModule*>::const_iterator moduleIt=alignModules.begin();
142 moduleIt!=alignModules.end(); ++moduleIt) {
143
144 // loop over AlignPar
145 DataVector<AlignPar>* alignPars=m_alignModuleTool->getAlignPars(*moduleIt);
146 for (DataVector<AlignPar>::iterator alignParIt=alignPars->begin();
147 alignParIt!=alignPars->end(); ++alignParIt) {
148
149 for (int ishift=0;ishift<2;ishift++) {
150
151 double shiftsize = shiftSize(*alignParIt);
152 if (ishift>0) shiftsize*=-1.;
153 m_alignModuleTool->shiftModule(*moduleIt,alignTrack,(**alignParIt).paramType(),shiftsize);
154 refittedTrack = (m_fitter->fit(ctx,
155 *trackForRefit,m_runOutlierRemoval,
156 m_particleHypothesis)).release();
157 m_alignModuleTool->restoreModule(*moduleIt);
158 if (!refittedTrack) {
159 msg(MSG::WARNING) << "track refit failed!"<<endmsg;
161 return false;
162 }
163
164 int nIter=alignCache.m_iterationsOfLastFit;
165 ATH_MSG_DEBUG("nIter: "<<nIter);
166 if (nIter>m_maxIter) {
167 ATH_MSG_DEBUG("exceeded maximum number of iterations");
169 return false;
170 }
171
172 if (nIter>m_nIterations) m_nIterations=nIter;
173 }
174 } // loop over AlignPar
175 } // loop over AlignModules
176
177 ATH_MSG_DEBUG("done with scanShifts, m_nIterations="<<m_nIterations);
178 return true;
179 }

◆ 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 265 of file ShiftingDerivCalcTool.cxx.

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

◆ 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 819 of file ShiftingDerivCalcTool.cxx.

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

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

◆ shiftSize()

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

Definition at line 805 of file ShiftingDerivCalcTool.cxx.

805 {
806 bool rotation =
807 alignPar->paramType() == AlignModule::RotX ||
808 alignPar->paramType() == AlignModule::RotY ||
809 alignPar->paramType() == AlignModule::RotZ;
810
811 double shift = rotation ? m_rotSize : m_traSize;
812
813 //ok... this is kind of ugly.
814 double sigma=alignPar->sigma();
815 return shift * sigma;
816}
virtual void shift(size_t pos, ptrdiff_t offs) override
Shift the elements of the container.

◆ 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: