ATLAS Offline Software
RefitSiOnlyTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // ================================================
7 // RefitSiOnly
8 // ================================================
9 //
10 // RefitSiOnlyTool.cxx
11 // Source file for RefitSiOnlyTool
12 //
13 // namespace InDetAlignment
14 //
15 // AlgTool to create refitted tracks with only silicon hits present
16 
18 
19 #include "Identifier/Identifier.h"
21 
22 //Track-things
23 #include "TrkTrack/Track.h"
28 
30 
32 
33 #include "RefitSiOnlyTool.h"
34 
35 namespace InDetAlignment {
36 
37  RefitSiOnlyTool::RefitSiOnlyTool (const std::string& type, const std::string& name, const IInterface* parent):
39  m_idHelper{},
40  m_ITrkFitter("Trk::KalmanFitter"),
41  m_comPar(nullptr),
42  m_ParticleHypothesis(Trk::nonInteracting),
43  m_trkindex{}
44  {
45  declareInterface<ICollectionProcessor>(this);
46  declareProperty("OutlierRemoval" , m_OutlierRemoval = true);
47  declareProperty("FitterTool" , m_ITrkFitter);
48  declareProperty("ParticleNumber" , m_ParticleNumber = 2);
49  declareProperty("Cosmic" , m_doCosmic = false);
50  declareProperty("StripPixelHits" , m_stripPixelHits = false);
51  declareProperty("StripSCTHits" , m_stripSCTHits = false);
52  declareProperty("StripTRTHits" , m_stripTRTHits = true);
53  }
54  //_________________________________________________________________________________________
55 
56  //destructor
58  //_________________________________________________________________________________________
59 
61  {
62  StatusCode sc;
63  ATH_MSG_DEBUG( "Initialize() of RefitSiOnlyTool" );
64 
65  // make for cosmic tracks new reference point
66  Amg::Vector3D refGP(0.,15000.,0.);
68 
69  //ID Helper
70  ATH_CHECK (detStore()->retrieve(m_idHelper,"AtlasID"));
71 
72  //Fitter
73  ATH_CHECK(m_ITrkFitter.retrieve());
74 
82 
83  if (msgLvl(MSG::DEBUG)) {
84  msg(MSG::DEBUG) << "ParticleNumber: " << m_ParticleNumber << endmsg;
85  msg(MSG::DEBUG) << "ParticleHypothesis: " << m_ParticleHypothesis << endmsg;
86  msg(MSG::DEBUG) << "Initialize() of RefitSiOnlyTool successful" << endmsg;
87  }
88 
89  return StatusCode::SUCCESS;
90  }
91  //_________________________________________________________________________________________
92 
94  {
95  ATH_MSG_DEBUG("Finalize() of RefitSiOnlyTool" );
96  return StatusCode::SUCCESS;
97  }
98  //_________________________________________________________________________________________
100  {
101  ATH_MSG_DEBUG( "nothing to configure - everything has already been configured in initialize()" );
102  return StatusCode::SUCCESS;
103  }
104  //_________________________________________________________________________________________
106  ATH_MSG_DEBUG( "processTrackCollection() of RefitSiOnlyTool" );
107 
108  m_trkindex=0;
110 
111  for (DataVector<Trk::Track>::const_iterator t=trks->begin(); t!=trks->end();++t) {
112  if (*t) {
113  Trk::Track* refittedTrack = refit(*t);
114 
115  if (refittedTrack==nullptr)
116  ATH_MSG_DEBUG( " Refit of the track " << m_trkindex << " did not work. Track skipped." );
117 
118  newTrks->push_back(refittedTrack);
119  } else {
120  newTrks->push_back(nullptr);
121  ATH_MSG_DEBUG( " Track " << m_trkindex << " is empty." );
122  }
123 
124  m_trkindex++;
125  }
126 
127  if (msgLvl(MSG::DEBUG)) {
128  dumpTrackCol(newTrks);
129  }
130 
131  return newTrks;
132  }
133 
134  //_________________________________________________________________________________________
136  // Step through all hits on a Trk::Track, pushback SiliconHits into RIO_Collection
137  // and Refit Track with SiliconHits
138  ATH_MSG_DEBUG( "Entering RefitSiOnlyTool::refit() for track #" << m_trkindex );
139 
140  const Trk::Perigee* initialPerigee = tr->perigeeParameters();
141  if (initialPerigee) {
142  ATH_MSG_DEBUG( "Track # " << m_trkindex << " has momentum before refit: "
143  << initialPerigee->momentum().mag() / CLHEP::GeV << " CLHEP::GeV/c" );
144  }
145  else { ATH_MSG_WARNING( "Track # " << m_trkindex << " without perigee" ); }
146 
147  Trk::Track* SiOnlyTrack = nullptr;
148  bool containsGangedPixels = false;
149  std::vector<const Trk::MeasurementBase*> MeasurementBase_Collection;
150 
151  ATH_MSG_DEBUG( "Building stripped RIO_Collection" );
153  measBase !=tr->measurementsOnTrack()->end(); ++measBase) {
154 
155  const Trk::RIO_OnTrack* rio = dynamic_cast <const Trk::RIO_OnTrack*>(*measBase);
156  if (rio != nullptr) {
157  const Identifier& surfaceID = (rio->identify());
158  if(filterHit(surfaceID)==false) {
159  MeasurementBase_Collection.push_back(*measBase);
160 
161  // protect against ganged Pixel Hits
162  if (rio->prepRawData()) {
163  const InDet::SiCluster* siHit = dynamic_cast <const InDet::SiCluster*>(rio->prepRawData());
164  if (siHit) {
165  if (siHit->gangedPixel()) {
166  containsGangedPixels = true;
167  ATH_MSG_DEBUG( " Reject track # " << m_trkindex
168  << " because it contains ganged pixel hits" );
169  }
170  }
171  }
172 
173  }
174  }
175  }
176 
177  // Do Silicon only Refit with Silicon only HitCollection and TrackParameters
178  // at StartingPoint of track
179  if (!containsGangedPixels) {
180  if (m_doCosmic) {
181  ATH_MSG_DEBUG("Refitting using Cosmic reference point");
182 
183  // order the parameters according to the Cosmics reference points
184  // works only for Si, not for TRT!
185  const Trk::TrackParameters* minPar =
186  *(std::min_element(tr->trackParameters()->begin(),
187  tr->trackParameters()->end(),
188  *m_comPar));
189 
190  SiOnlyTrack = m_ITrkFitter
191  ->fit(Gaudi::Hive::currentContext(),
192  MeasurementBase_Collection,
193  *minPar,
196  .release();
197  } // m_doCosmic
198  else {
199  SiOnlyTrack = m_ITrkFitter
200  ->fit(Gaudi::Hive::currentContext(),
201  MeasurementBase_Collection,
202  *(tr->trackParameters()->front()),
205  .release();
206  }
207  }
208  else {
209  ATH_MSG_DEBUG(" No refit was done for track # " << m_trkindex);
210  return nullptr;
211  }
212 
213  return SiOnlyTrack;
214  }
215 
216 
217  //_________________________________________________________________________________________
219  {
220  if (m_idHelper->is_sct(id) && m_stripSCTHits) {return true;}
221  else if (m_idHelper->is_pixel(id) && m_stripPixelHits) {return true;}
222  else if (m_idHelper->is_trt(id) && m_stripTRTHits) {return true;}
223  else {return false;}
224  }
225 
226 
227  //_________________________________________________________________________________________
229  ATH_MSG_DEBUG( "In dumpTrackCol() with size=" << tracks->size() );
230 
231  int itrk = 0;
233  it!=tracks->end();++it) {
234 
235  if(*it!=nullptr){
236 
237  const Trk::Perigee* aMeasPer = (*it)->perigeeParameters();
238  if (aMeasPer==nullptr){
239  ATH_MSG_ERROR( "Could not get Trk::MeasuredPerigee" );}
240  else {
241  double d0 = aMeasPer->parameters()[Trk::d0];
242  double z0 = aMeasPer->parameters()[Trk::z0];
243  double phi0 = aMeasPer->parameters()[Trk::phi0];
244  double theta = aMeasPer->parameters()[Trk::theta];
245  double qOverP = aMeasPer->parameters()[Trk::qOverP];
246  if (msgLvl(MSG::DEBUG)) {
247  msg(MSG::DEBUG) << itrk << ". Track Parameters (d0,z0,phi0,theta,qOverP)" << endmsg;
248  msg(MSG::DEBUG) << " " << d0 << ", " << z0 << ", "
249  << phi0 << ", " << theta << ", " << qOverP << endmsg;
250  msg(MSG::DEBUG) << " - momentum: "
251  << aMeasPer->momentum().mag() / CLHEP::GeV << " CLHEP::GeV/c" << endmsg;
252  }
253  }
254  }
255  itrk++;
256  }
257  }
258 } //namespace
RefitSiOnlyTool.h
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
InDetAlignment::RefitSiOnlyTool::dumpTrackCol
void dumpTrackCol(DataVector< Trk::Track > *tracks)
Definition: RefitSiOnlyTool.cxx:228
AtlasDetectorID::is_pixel
bool is_pixel(Identifier id) const
Definition: AtlasDetectorID.h:760
Trk::noHypothesis
@ noHypothesis
Definition: ParticleHypothesis.h:37
InDetAlignment::RefitSiOnlyTool::filterHit
bool filterHit(const Identifier &id) const
determines from flags, if this hit should be included in the fit or not
Definition: RefitSiOnlyTool.cxx:218
Trk::proton
@ proton
Definition: ParticleHypothesis.h:31
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
InDetAlignment::RefitSiOnlyTool::m_ParticleHypothesis
Trk::ParticleHypothesis m_ParticleHypothesis
Definition: RefitSiOnlyTool.h:73
TrackParameters.h
InDetAlignment::RefitSiOnlyTool::~RefitSiOnlyTool
virtual ~RefitSiOnlyTool()
Definition: RefitSiOnlyTool.cxx:57
MeasurementBase.h
InDetAlignment::RefitSiOnlyTool::refit
Trk::Track * refit(const Trk::Track *tr) const
refits a track not using non-silicon hits
Definition: RefitSiOnlyTool.cxx:135
InDetAlignment::RefitSiOnlyTool::configure
virtual StatusCode configure()
does necessary configuration to the tool
Definition: RefitSiOnlyTool.cxx:99
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
InDetAlignment::RefitSiOnlyTool::m_stripSCTHits
bool m_stripSCTHits
flag to not consider SCT hits in the refit
Definition: RefitSiOnlyTool.h:68
AtlasDetectorID::is_sct
bool is_sct(Identifier id) const
Definition: AtlasDetectorID.h:770
InDetAlignment::RefitSiOnlyTool::finalize
virtual StatusCode finalize()
Athena Tool methods.
Definition: RefitSiOnlyTool.cxx:93
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
InDetAlignment
Definition: CreateMisalignAlg.cxx:68
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Trk::z0
@ z0
Definition: ParamDefs.h:64
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
InDetAlignment::RefitSiOnlyTool::m_ParticleNumber
int m_ParticleNumber
Definition: RefitSiOnlyTool.h:72
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
InDetAlignment::RefitSiOnlyTool::m_comPar
Trk::TrkParametersComparisonFunction * m_comPar
Definition: RefitSiOnlyTool.h:63
AtlasDetectorID::is_trt
bool is_trt(Identifier id) const
Definition: AtlasDetectorID.h:782
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
InDetAccessor::qOverP
@ qOverP
perigee
Definition: InDetAccessor.h:35
PrepRawData.h
InDetAlignment::RefitSiOnlyTool::m_stripTRTHits
bool m_stripTRTHits
flag to not consider TRT hits in the refit
Definition: RefitSiOnlyTool.h:70
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
Track.h
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
InDetAlignment::RefitSiOnlyTool::initialize
virtual StatusCode initialize()
Athena Tool methods.
Definition: RefitSiOnlyTool.cxx:60
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InDetAlignment::RefitSiOnlyTool::m_OutlierRemoval
bool m_OutlierRemoval
flag for outlier removal
Definition: RefitSiOnlyTool.h:66
Trk::theta
@ theta
Definition: ParamDefs.h:66
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::electron
@ electron
Definition: ParticleHypothesis.h:27
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDetAlignment::RefitSiOnlyTool::m_doCosmic
bool m_doCosmic
Flag for cosmics.
Definition: RefitSiOnlyTool.h:65
Trk::pion
@ pion
Definition: ParticleHypothesis.h:29
TRT::Track::d0
@ d0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:62
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
TRT::Track::z0
@ z0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:63
Trk::muon
@ muon
Definition: ParticleHypothesis.h:28
DataVector< Trk::Track >
Trk::Track::trackParameters
const DataVector< const TrackParameters > * trackParameters() const
Return a pointer to a vector of TrackParameters.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:97
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
InDet::SiCluster::gangedPixel
bool gangedPixel() const
return the flag of this cluster containing a gangedPixel
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::d0
@ d0
Definition: ParamDefs.h:63
RIO_OnTrack.h
Trk::nonInteracting
@ nonInteracting
Definition: ParticleHypothesis.h:25
SiCluster.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
InDetAlignment::RefitSiOnlyTool::m_stripPixelHits
bool m_stripPixelHits
flag to not consider Pixel hits in the refit
Definition: RefitSiOnlyTool.h:69
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::RIO_OnTrack::prepRawData
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Trk::kaon
@ kaon
Definition: ParticleHypothesis.h:30
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::Track::measurementsOnTrack
const DataVector< const MeasurementBase > * measurementsOnTrack() const
return a pointer to a vector of MeasurementBase (NOT including any that come from outliers).
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:178
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
InDetAlignment::RefitSiOnlyTool::m_idHelper
const AtlasDetectorID * m_idHelper
Definition: RefitSiOnlyTool.h:49
InDetAlignment::RefitSiOnlyTool::m_ITrkFitter
ToolHandle< Trk::ITrackFitter > m_ITrkFitter
Definition: RefitSiOnlyTool.h:61
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::TrkParametersComparisonFunction
ComparisonFunction< TrackParameters > TrkParametersComparisonFunction
Definition: TrkParametersComparisonFunction.h:26
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trk::RIO_OnTrack::identify
Identifier identify() const
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:152
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:67
InDetAlignment::RefitSiOnlyTool::m_trkindex
int m_trkindex
Definition: RefitSiOnlyTool.h:74
AthAlgTool
Definition: AthAlgTool.h:26
InDetAlignment::RefitSiOnlyTool::RefitSiOnlyTool
RefitSiOnlyTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: RefitSiOnlyTool.cxx:37
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ITrackFitter.h
InDet::SiCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SiCluster.h:40
Trk::phi0
@ phi0
Definition: ParamDefs.h:65
InDetAlignment::RefitSiOnlyTool::processTrackCollection
virtual const DataVector< Trk::Track > * processTrackCollection(const DataVector< Trk::Track > *trks)
main processing of track collection - refits a track using only filtered hits (e.g.
Definition: RefitSiOnlyTool.cxx:105
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Identifier
Definition: IdentifierFieldParser.cxx:14