41#include "Identifier/Identifier.h"
105 ATH_CHECK(
m_assoTool.retrieve( DisableTool{ m_assoTool.empty() || (m_trkSummaryTool.empty() && m_assoMapName.empty()) } ));
108 return StatusCode::SUCCESS;
122 ATH_MSG_INFO(
"Real tracks with " << mitr.first <<
" hits: " << mitr.second);
125 ATH_MSG_INFO(
"Fake tracks with " << mitr.first <<
" hits: " << mitr.second);
134 return StatusCode::SUCCESS;
139 int segmentCounter=0;
140 const EventContext& ctx = Gaudi::Hive::currentContext();
145 StatusCode
sc = StatusCode::SUCCESS;
154 if (!inputSegments.
isValid()) {
156 sc = StatusCode::FAILURE;
164 ATH_CHECK(final_outputTrackCollection.
record(std::make_unique<TrackCollection>()));
166 std::vector<std::unique_ptr<Trk::Track> > output_track_collection;
172 if (!truthCollectionTRT.
isValid()){
174 return StatusCode::FAILURE;
183 for(iseg=inputSegments->begin(); iseg != isegEnd; ++ iseg) {
188 if((*iseg)->numberOfMeasurementBases()<10)
continue;
191 for(
unsigned int i=0;i<(*iseg)->numberOfMeasurementBases();++i){
192 const Amg::VectorX& LocalParameters = (*iseg)->measurement(i)->localParameters();
193 const Amg::MatrixX& LocalErrorMatrix = (*iseg)->measurement(i)->localCovariance();
194 double z=(*iseg)->measurement(i)->globalPosition().z();
195 ATH_MSG_DEBUG(
"Segment "<<segmentCounter<<
" rioOnTrack "<<i<<
" (z="<<
z<<
") : "<<LocalParameters[0]
197 myset.push_back((*iseg)->measurement(i));
200 if((*iseg)->numberOfMeasurementBases()>0){
201 ATH_MSG_DEBUG(
"numberOfContainedRots: " << (*iseg)->numberOfMeasurementBases());
212 ATH_MSG_DEBUG(
"No straightLineSurface !! Trying Perigee ...");
216 ATH_MSG_DEBUG(
"Associated surface dynamic_cast into PerigeeSurface failed: "<<(*iseg)->associatedSurface());
217 ATH_MSG_DEBUG(
"Leaving input matching perigee as nullptr, will not get a fittedTrack");
220 inputMatchPerigee =
new Trk::Perigee(p(0),p(1),p(2),p(3),p(4), *testPSf);
226 int nmeas=(*iseg)->numberOfMeasurementBases();
227 Amg::Vector3D surfpos(.5*((*iseg)->measurement(nmeas/2)->globalPosition()+(*iseg)->measurement(nmeas/2+1)->globalPosition()));
229 std::unique_ptr<const Trk::TrackParameters> tmp =
230 m_extrapolator->extrapolateDirectly(ctx, *inputMatchLine, persurf);
232 inputMatchPerigee =
static_cast<const Trk::Perigee*
>(tmp.release());
237 std::unique_ptr<Trk::Track> fittedTrack;
239 if (inputMatchPerigee) inputpar=inputMatchPerigee;
240 else if (inputMatchLine) inputpar=inputMatchLine;
254 for ( ; itSet!=itSetEnd; ++itSet) {
256 mindist=(**itSet).trackParameters()->position().perp();
257 measpar=(**itSet).trackParameters();
260 std::unique_ptr<Trk::TrackParameters> myper;
268 auto trajectory = std::make_unique<Trk::TrackStates>();
269 itSet = fittedTrack->trackStateOnSurfaces()->begin();
270 for ( ; itSet!=itSetEnd; ++itSet) {
272 auto trackpar=(**itSet).trackParameters() ? (**itSet).trackParameters()->uniqueClone() :
nullptr;
273 auto measurement=(**itSet).measurementOnTrack() ? (**itSet).measurementOnTrack()->uniqueClone() :
nullptr;
274 auto fitQual=(**itSet).fitQualityOnSurface() ;
275 auto mateff=(**itSet).materialEffectsOnTrack() ? (**itSet).materialEffectsOnTrack()->uniqueClone() :
nullptr;
276 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern(0);
281 trajectory->push_back(
283 std::move(measurement),
290 itSet = trajectory->begin()+1;
291 itSetEnd = trajectory->end();
292 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern(0);
294 const auto myPosition {myper->position()};
295 const auto myMomentum {myper->momentum()};
303 for ( ; itSet!=itSetEnd; ++itSet) {
304 double inprod1=((**itSet).trackParameters()->position()-myPosition).dot(myMomentum);
306 double inprod2=((**itSet).trackParameters()->position()-myPosition).dot(myMomentum);
308 if (inprod1>0 && inprod2<0) {
309 trajectory->insert(trajectory->begin()+
index,pertsos);
316 itSet = trajectory->begin();
317 double inprod=((**itSet).trackParameters()->position()-myPosition).dot(myMomentum);
318 if (inprod>0) trajectory->insert(trajectory->begin(),pertsos);
319 else trajectory->push_back(pertsos);
321 std::unique_ptr<Trk::Track> track =
322 std::make_unique<Trk::Track>(fittedTrack->info(),
323 std::move(trajectory),
324 fittedTrack->fitQuality()->uniqueClone());
325 fittedTrack = std::move(track);
330 int nHT=
nHTHits(fittedTrack.get());
333 if ((*iseg)->fitQuality())
ATH_MSG_DEBUG(
"Quality of Segment: chi^2 /ndof "<<(*iseg)->fitQuality()->chiSquared()<<
" / "<<(*iseg)->fitQuality()->numberDoF());
334 ATH_MSG_DEBUG(
"Quality of Track: chi^2 /ndof "<<fittedTrack->fitQuality()->chiSquared()<<
" / "<<fittedTrack->fitQuality()->numberDoF());
342 int nhits=(*iseg)->numberOfMeasurementBases();
343 ATH_MSG_DEBUG(
"Real/Noise : "<< truefraction <<
" chi2="<<fittedTrack->fitQuality()->chiSquared()/
double(fittedTrack->fitQuality()->numberDoF()));
344 if(truefraction>0.5){
367 output_track_collection.push_back(std::move(fittedTrack));
376 delete inputMatchLine;
377 delete inputMatchPerigee;
382 std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map;
385 prd_to_track_map =
m_assoTool->createPRDtoTrackMap();
388 if (!input_asso_map.
isValid()) {
391 *prd_to_track_map = *input_asso_map;
394 for (
const std::unique_ptr<Trk::Track> &track : output_track_collection) {
399 final_outputTrackCollection->reserve(output_track_collection.size());
401 for (std::unique_ptr<Trk::Track> &track : output_track_collection) {
402 m_trkSummaryTool->computeAndReplaceTrackSummary(*track,prd_to_track_map.get());
403 final_outputTrackCollection->push_back(std::move(track));
407 for (std::unique_ptr<Trk::Track> &track : output_track_collection) {
408 final_outputTrackCollection->push_back(std::move(track));
415 if (!final_outputTrackCollection.
isValid()) {
418 return StatusCode::FAILURE;
428 using iter = PRD_MultiTruthCollection::const_iterator;
434 if(truthCollectionTRT.
isValid()){
435 std::pair<iter,iter> range = truthCollectionTRT->equal_range(driftcircle->
identify());
436 numBarcodes+=std::distance(range.first,range.second);
467 if(nreal>0) nDriftReal++;
477 fraction=double(nDriftReal)/double(nDriftNoise+nDriftReal);
492 if (hitOnTrack !=
nullptr) {
520 if (hitOnTrack !=
nullptr) {
566 fraction=double(nDriftReal)/double(nDriftNoise+nDriftReal);
579 int n_combined_fit=0;
586 sc = outputCombiCollection.
record(std::make_unique<TrackCollection>());
587 if (
sc.isFailure())
return;
589 if (!BarrelSegments.
isValid()){
594 if (!EndcapSegments.
isValid()) {
599 ATH_MSG_VERBOSE(
"Got both barrel and endcap segment collections of size "<<BarrelSegments->size()<<
" "<<EndcapSegments->size());
605 for(;iseg!=isegE;++iseg,scount++){
609 iseg = EndcapSegments->begin();
610 isegE = EndcapSegments->end();
613 for(;iseg!=isegE;++iseg,scount++){
617 if(BarrelSegments->size()==1 && EndcapSegments->size()==1){
618 ATH_MSG_VERBOSE(
"Here we go: one barrel segment and one endcap segment!");
627 for(;isegBarrel!=isegBarrelE;++isegBarrel){
628 for(;isegEndcap!=isegEndcapE;++isegEndcap){
630 std::vector< Trk::PseudoMeasurementOnTrack*> tobedeleted;
632 ATH_MSG_VERBOSE(
"Barrel Segment : phi="<<(*isegBarrel)->localParameters()[
Trk::phi]<<
" with "<<(*isegBarrel)->numberOfMeasurementBases()<<
" hits");
633 ATH_MSG_VERBOSE(
"Endcap Segment : phi="<<(*isegEndcap)->localParameters()[
Trk::phi]<<
" with "<<(*isegEndcap)->numberOfMeasurementBases()<<
" hits");
638 bool barreldown=((*isegBarrel)->measurement((*isegBarrel)->numberOfMeasurementBases()/2)->globalPosition().y()<0);
640 if((*isegEndcap)->localParameters().contains(
Trk::theta)){
645 if(( (*isegEndcap)->globalPosition().y()>0 && (*isegEndcap)->globalPosition().z()>0) ||
646 ((*isegEndcap)->globalPosition().y()<0 && (*isegEndcap)->globalPosition().z()<0)
664 if(!barreldown && (*isegEndcap)->globalPosition().y()>0){
665 ATH_MSG_VERBOSE(
"Both barrel and endcap segments in top sectors, won't fit");
669 if(barreldown && (*isegEndcap)->globalPosition().y()<0){
670 ATH_MSG_VERBOSE(
"Both barrel and endcap segments in lower sectors, won't fit");
673 int firstechit=0,lastechit=0;
674 if((*isegEndcap)->globalPosition().y()>0){
676 for(
int i=0;i<(int)echits.size();++i){
686 myset.push_back(meas);
694 for(
unsigned int i=0;i<(*isegBarrel)->numberOfMeasurementBases();++i){
695 const Amg::VectorX LocalParameters = (*isegBarrel)->measurement(i)->localParameters();
696 const Amg::MatrixX LocalErrorMatrix = (*isegBarrel)->measurement(i)->localCovariance();
697 double z=(*isegBarrel)->measurement(i)->globalPosition().z();
698 double phi=(*isegBarrel)->measurement(i)->globalPosition().phi();
699 double r=(*isegBarrel)->measurement(i)->globalPosition().perp();
704 myset.push_back((*isegBarrel)->measurement(i));
712 for(
unsigned int i=0;i<(*isegBarrel)->numberOfMeasurementBases();++i){
713 const Amg::VectorX LocalParameters = (*isegBarrel)->measurement(i)->localParameters();
714 const Amg::MatrixX LocalErrorMatrix = (*isegBarrel)->measurement(i)->localCovariance();
715 double z=(*isegBarrel)->measurement(i)->globalPosition().z();
716 double phi=(*isegBarrel)->measurement(i)->globalPosition().phi();
717 double r=(*isegBarrel)->measurement(i)->globalPosition().perp();
722 myset.push_back((*isegBarrel)->measurement(i));
730 for(
int i=0;i<(int)echits.size();++i){
740 myset.push_back(meas);
751 Amg::Vector3D inputMatchingPos((*isegBarrel)->globalPosition());
753 if((*isegEndcap)->globalPosition().y()>0)
754 inputMatchingPos=(*isegEndcap)->globalPosition();
759 if((*isegBarrel)->localParameters().contains(
Trk::qOverP)){
760 p = ((*isegBarrel)->localParameters()[
Trk::qOverP]!=0.) ? fabs(1./((*isegBarrel)->localParameters()[
Trk::qOverP])) : 10e7;
764 if((*isegBarrel)->localParameters().contains(
Trk::phi)){
774 ATH_MSG_VERBOSE(
"Global position: "<<inputMatchingPos<<
" Globalmomentum: "<<inputMatchingMom);
779 Trk::MeasurementSet::const_iterator mit;
780 Trk::MeasurementSet::const_iterator mitE=myset.end();
783 for(mit=myset.begin();mit!=mitE;++mit){
784 myset2.push_back(*mit);
785 if(count2==firstechit || count2==lastechit){
793 if ((count2==firstechit && firstechit!=0) || (count2==lastechit && firstechit==0)) locz=200;
807 if(fabs(gpos.z())>800){
819 T = line->transform().rotation();
827 tobedeleted.push_back(pseudo);
831 myset2.push_back(pseudo);
841 if((*isegEndcap)->globalPosition().y()>0){
856 ATH_MSG_VERBOSE(
"Associated surface dynamic_cast into PerigeeSurface failed. "<<(*isegBarrel)->associatedSurface());
857 ATH_MSG_VERBOSE(
"Leaving input matching perigee as nullptr, will not get a fittedTrack");
860 inputMatchPerigee =
new Trk::Perigee(inputMatchingPos,inputMatchingMom, 1., *testPSf);
869 std::unique_ptr<Trk::Track> fittedTrack;
878 }
else if (inputMatchPerigee){
894 }
else if (inputMatchPerigee){
907 ATH_MSG_DEBUG(
"Quality of Track: "<<fittedTrack->fitQuality()->chiSquared()<<
" / "<<fittedTrack->fitQuality()->numberDoF());
909 outputCombiCollection->push_back(std::move(fittedTrack));
912 delete inputMatchPerigee;
913 delete inputMatchLine;
915 for(
size_t i=0;i<tobedeleted.size();i++)
916 delete tobedeleted[i];
923 if (!outputCombiCollection.
isValid()) {
924 ATH_MSG_ERROR(
"Could not write track Barrel+EC collection TRT_Barrel_EC");
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
#define CHECK(...)
Evaluate an expression and check for errors.
An STL vector of pointers that by default owns its pointed-to elements.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
This is an Identifier helper class for the TRT subdetector.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
DataModel_detail::const_iterator< DataVector > const_iterator
Represents 'corrected' measurements from the TRT (for example, corrected for wire sag).
bool highLevel() const
returns true if the high level threshold was passed
virtual const TRT_DriftCircle * prepRawData() const override final
returns the PrepRawData - is a TRT_DriftCircle in this scope
virtual const Trk::Surface & associatedSurface() const override final
returns the surface for the local to global transformation
bool isNoise() const
returns true if the hit is caused by noise with a high probability.
int m_nTracksReal
Counter for real reconstructed Tracks.
double getNoiseProbability(const Trk::Track *track) const
Get the fraction of noise TRT hits on this Track.
std::atomic< int > m_events
Event counter.
ToolHandle< Trk::ITrackFitter > m_trackFitter
The TrackFitter.
int nHTHits(const Trk::Track *track) const
Count number of TRT HT Hits on track.
SG::ReadHandleKey< Trk::SegmentCollection > m_endcapSegments
Name of Endcap segment collection.
ToolHandle< Trk::IExtrapolator > m_extrapolator
The Extrapolator.
SG::ReadHandleKey< Trk::SegmentCollection > m_inputSegmentCollectionName
Name of the TrackSegment Collection to read in.
const AtlasDetectorID * m_idHelper
double getRealFractionTRT(const Trk::Track *track, const EventContext &ctx) const
Get the fraction of truth TRT hits on this Track.
ToolHandle< Trk::IPRDtoTrackMapTool > m_assoTool
void combineSegments(const EventContext &ctx) const
int m_minTRTHits
All tracks with less Hits (after the track fit) will be thrown away.
SG::ReadHandleKey< PRD_MultiTruthCollection > m_multiTruthCollectionTRTName
Name of the TRT MultiTruthCollection.
std::map< int, int > m_MapReal
Map of hits and real tracks.
int m_nTracksFake
Counter for fake reconstructed Track.
std::atomic< int > m_n_combined_fit
std::map< int, int > m_MapFake
Map of hits and fake tracks.
int getNumberReal(const InDet::TRT_DriftCircle *, const EventContext &ctx) const
Get the number of truth particles associated with this hit.
SG::WriteHandleKey< TrackCollection > m_BECCollectionName
Name of the combined (TRT Barrel+EC) TrackCollection to write out.
SG::ReadHandleKey< Trk::SegmentCollection > m_barrelSegments
Name of Barrel segment collection.
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trkSummaryTool
bool m_outlierRemoval
Flag to switch on the outlier removal in the track fitter.
SG::ReadHandleKey< Trk::PRDtoTrackMap > m_inputAssoMapName
key to be set to optionally store PRD to track association map
SG::WriteHandleKey< TrackCollection > m_outputTrackCollectionName
Name of the TrackCollection to write out.
TRT_SegmentsToTrack(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteHandleKey< Trk::PRDtoTrackMap > m_assoMapName
key for the PRDtoTrackMap to filled by the ambiguity score processor.
int nTRTHits(const Trk::Track *track) const
Count number of TRT Hits on track.
bool m_combineSegments
Try to combine segments from Barrel and Endcap.
double m_noiseCut
All tracks with a TRT Noise fraction larger than this variable will be thrown away.
bool m_materialEffects
Flag to switch on Material Effects in the Fitter.
double m_noiseratio
average percentage of noise in real tracks
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
virtual const Amg::Vector3D & globalPosition() const =0
Interface method to get the global Position.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
Class describing the Line to which the Perigee refers to.
Identifier identify() const
return the identifier
Class to handle pseudo-measurements in fitters and on track objects.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Identifier identify() const
return the identifier -extends MeasurementBase
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ BremPoint
This represents a brem point on the track, and so will contain TrackParameters and MaterialEffectsBas...
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
std::vector< const MeasurementBase * > MeasurementSet
vector of fittable measurements
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
@ pz
global momentum (cartesian)
std::pair< double, ParamDefs > DefinedParameter
Typedef to of a std::pair<double, ParamDefs> to identify a passed-through double as a specific type o...
ParametersBase< TrackParametersDim, Charged > TrackParameters
void reverse(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of reverse for DataVector/List.