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;
144 StatusCode
sc = StatusCode::SUCCESS;
153 if (!inputSegments.
isValid()) {
155 sc = StatusCode::FAILURE;
163 ATH_CHECK(final_outputTrackCollection.
record(std::make_unique<TrackCollection>()));
165 std::vector<std::unique_ptr<Trk::Track> > output_track_collection;
171 if (!truthCollectionTRT.
isValid()){
173 return StatusCode::FAILURE;
182 for(iseg=inputSegments->begin(); iseg != isegEnd; ++ iseg) {
187 if((*iseg)->numberOfMeasurementBases()<10)
continue;
190 for(
unsigned int i=0;i<(*iseg)->numberOfMeasurementBases();++i){
191 const Amg::VectorX& LocalParameters = (*iseg)->measurement(i)->localParameters();
192 const Amg::MatrixX& LocalErrorMatrix = (*iseg)->measurement(i)->localCovariance();
193 double z=(*iseg)->measurement(i)->globalPosition().z();
194 ATH_MSG_DEBUG(
"Segment "<<segmentCounter<<
" rioOnTrack "<<i<<
" (z="<<
z<<
") : "<<LocalParameters[0]
196 myset.push_back((*iseg)->measurement(i));
199 if((*iseg)->numberOfMeasurementBases()>0){
200 ATH_MSG_DEBUG(
"numberOfContainedRots: " << (*iseg)->numberOfMeasurementBases());
211 ATH_MSG_DEBUG(
"No straightLineSurface !! Trying Perigee ...");
215 ATH_MSG_DEBUG(
"Associated surface dynamic_cast into PerigeeSurface failed: "<<(*iseg)->associatedSurface());
216 ATH_MSG_DEBUG(
"Leaving input matching perigee as nullptr, will not get a fittedTrack");
219 inputMatchPerigee =
new Trk::Perigee(p(0),p(1),p(2),p(3),p(4), *testPSf);
225 int nmeas=(*iseg)->numberOfMeasurementBases();
226 Amg::Vector3D surfpos(.5*((*iseg)->measurement(nmeas/2)->globalPosition()+(*iseg)->measurement(nmeas/2+1)->globalPosition()));
228 std::unique_ptr<const Trk::TrackParameters> tmp =
229 m_extrapolator->extrapolateDirectly(ctx, *inputMatchLine, persurf);
231 inputMatchPerigee =
static_cast<const Trk::Perigee*
>(tmp.release());
236 std::unique_ptr<Trk::Track> fittedTrack;
238 if (inputMatchPerigee) inputpar=inputMatchPerigee;
239 else if (inputMatchLine) inputpar=inputMatchLine;
253 for ( ; itSet!=itSetEnd; ++itSet) {
255 mindist=(**itSet).trackParameters()->position().perp();
256 measpar=(**itSet).trackParameters();
259 std::unique_ptr<Trk::TrackParameters> myper;
267 auto trajectory = std::make_unique<Trk::TrackStates>();
268 itSet = fittedTrack->trackStateOnSurfaces()->begin();
269 for ( ; itSet!=itSetEnd; ++itSet) {
271 auto trackpar=(**itSet).trackParameters() ? (**itSet).trackParameters()->uniqueClone() :
nullptr;
272 auto measurement=(**itSet).measurementOnTrack() ? (**itSet).measurementOnTrack()->uniqueClone() :
nullptr;
273 auto fitQual=(**itSet).fitQualityOnSurface() ;
274 auto mateff=(**itSet).materialEffectsOnTrack() ? (**itSet).materialEffectsOnTrack()->uniqueClone() :
nullptr;
275 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern(0);
280 trajectory->push_back(
282 std::move(measurement),
289 itSet = trajectory->begin()+1;
290 itSetEnd = trajectory->end();
291 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern(0);
293 const auto myPosition {myper->position()};
294 const auto myMomentum {myper->momentum()};
302 for ( ; itSet!=itSetEnd; ++itSet) {
303 double inprod1=((**itSet).trackParameters()->position()-myPosition).dot(myMomentum);
305 double inprod2=((**itSet).trackParameters()->position()-myPosition).dot(myMomentum);
307 if (inprod1>0 && inprod2<0) {
308 trajectory->insert(trajectory->begin()+
index,pertsos);
315 itSet = trajectory->begin();
316 double inprod=((**itSet).trackParameters()->position()-myPosition).dot(myMomentum);
317 if (inprod>0) trajectory->insert(trajectory->begin(),pertsos);
318 else trajectory->push_back(pertsos);
320 std::unique_ptr<Trk::Track> track =
321 std::make_unique<Trk::Track>(fittedTrack->info(),
322 std::move(trajectory),
323 fittedTrack->fitQuality()->uniqueClone());
324 fittedTrack = std::move(track);
329 int nHT=
nHTHits(fittedTrack.get());
332 if ((*iseg)->fitQuality())
ATH_MSG_DEBUG(
"Quality of Segment: chi^2 /ndof "<<(*iseg)->fitQuality()->chiSquared()<<
" / "<<(*iseg)->fitQuality()->numberDoF());
333 ATH_MSG_DEBUG(
"Quality of Track: chi^2 /ndof "<<fittedTrack->fitQuality()->chiSquared()<<
" / "<<fittedTrack->fitQuality()->numberDoF());
341 int nhits=(*iseg)->numberOfMeasurementBases();
342 ATH_MSG_DEBUG(
"Real/Noise : "<< truefraction <<
" chi2="<<fittedTrack->fitQuality()->chiSquared()/
double(fittedTrack->fitQuality()->numberDoF()));
343 if(truefraction>0.5){
366 output_track_collection.push_back(std::move(fittedTrack));
375 delete inputMatchLine;
376 delete inputMatchPerigee;
381 std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map;
384 prd_to_track_map =
m_assoTool->createPRDtoTrackMap();
387 if (!input_asso_map.
isValid()) {
390 *prd_to_track_map = *input_asso_map;
393 for (
const std::unique_ptr<Trk::Track> &track : output_track_collection) {
398 final_outputTrackCollection->reserve(output_track_collection.size());
400 for (std::unique_ptr<Trk::Track> &track : output_track_collection) {
401 m_trkSummaryTool->computeAndReplaceTrackSummary(ctx, *track,prd_to_track_map.get());
402 final_outputTrackCollection->push_back(std::move(track));
406 for (std::unique_ptr<Trk::Track> &track : output_track_collection) {
407 final_outputTrackCollection->push_back(std::move(track));
414 if (!final_outputTrackCollection.
isValid()) {
417 return StatusCode::FAILURE;
427 using iter = PRD_MultiTruthCollection::const_iterator;
433 if(truthCollectionTRT.
isValid()){
434 std::pair<iter,iter> range = truthCollectionTRT->equal_range(driftcircle->
identify());
435 numBarcodes+=std::distance(range.first,range.second);
466 if(nreal>0) nDriftReal++;
476 fraction=double(nDriftReal)/double(nDriftNoise+nDriftReal);
491 if (hitOnTrack !=
nullptr) {
519 if (hitOnTrack !=
nullptr) {
565 fraction=double(nDriftReal)/double(nDriftNoise+nDriftReal);
578 int n_combined_fit=0;
585 sc = outputCombiCollection.
record(std::make_unique<TrackCollection>());
586 if (
sc.isFailure())
return;
588 if (!BarrelSegments.
isValid()){
593 if (!EndcapSegments.
isValid()) {
598 ATH_MSG_VERBOSE(
"Got both barrel and endcap segment collections of size "<<BarrelSegments->size()<<
" "<<EndcapSegments->size());
604 for(;iseg!=isegE;++iseg,scount++){
608 iseg = EndcapSegments->begin();
609 isegE = EndcapSegments->end();
612 for(;iseg!=isegE;++iseg,scount++){
616 if(BarrelSegments->size()==1 && EndcapSegments->size()==1){
617 ATH_MSG_VERBOSE(
"Here we go: one barrel segment and one endcap segment!");
626 for(;isegBarrel!=isegBarrelE;++isegBarrel){
627 for(;isegEndcap!=isegEndcapE;++isegEndcap){
629 std::vector< Trk::PseudoMeasurementOnTrack*> tobedeleted;
631 ATH_MSG_VERBOSE(
"Barrel Segment : phi="<<(*isegBarrel)->localParameters()[
Trk::phi]<<
" with "<<(*isegBarrel)->numberOfMeasurementBases()<<
" hits");
632 ATH_MSG_VERBOSE(
"Endcap Segment : phi="<<(*isegEndcap)->localParameters()[
Trk::phi]<<
" with "<<(*isegEndcap)->numberOfMeasurementBases()<<
" hits");
637 bool barreldown=((*isegBarrel)->measurement((*isegBarrel)->numberOfMeasurementBases()/2)->globalPosition().y()<0);
639 if((*isegEndcap)->localParameters().contains(
Trk::theta)){
644 if(( (*isegEndcap)->globalPosition().y()>0 && (*isegEndcap)->globalPosition().z()>0) ||
645 ((*isegEndcap)->globalPosition().y()<0 && (*isegEndcap)->globalPosition().z()<0)
663 if(!barreldown && (*isegEndcap)->globalPosition().y()>0){
664 ATH_MSG_VERBOSE(
"Both barrel and endcap segments in top sectors, won't fit");
668 if(barreldown && (*isegEndcap)->globalPosition().y()<0){
669 ATH_MSG_VERBOSE(
"Both barrel and endcap segments in lower sectors, won't fit");
672 int firstechit=0,lastechit=0;
673 if((*isegEndcap)->globalPosition().y()>0){
675 for(
int i=0;i<(int)echits.size();++i){
685 myset.push_back(meas);
693 for(
unsigned int i=0;i<(*isegBarrel)->numberOfMeasurementBases();++i){
694 const Amg::VectorX LocalParameters = (*isegBarrel)->measurement(i)->localParameters();
695 const Amg::MatrixX LocalErrorMatrix = (*isegBarrel)->measurement(i)->localCovariance();
696 double z=(*isegBarrel)->measurement(i)->globalPosition().z();
697 double phi=(*isegBarrel)->measurement(i)->globalPosition().phi();
698 double r=(*isegBarrel)->measurement(i)->globalPosition().perp();
703 myset.push_back((*isegBarrel)->measurement(i));
711 for(
unsigned int i=0;i<(*isegBarrel)->numberOfMeasurementBases();++i){
712 const Amg::VectorX LocalParameters = (*isegBarrel)->measurement(i)->localParameters();
713 const Amg::MatrixX LocalErrorMatrix = (*isegBarrel)->measurement(i)->localCovariance();
714 double z=(*isegBarrel)->measurement(i)->globalPosition().z();
715 double phi=(*isegBarrel)->measurement(i)->globalPosition().phi();
716 double r=(*isegBarrel)->measurement(i)->globalPosition().perp();
721 myset.push_back((*isegBarrel)->measurement(i));
729 for(
int i=0;i<(int)echits.size();++i){
739 myset.push_back(meas);
750 Amg::Vector3D inputMatchingPos((*isegBarrel)->globalPosition());
752 if((*isegEndcap)->globalPosition().y()>0)
753 inputMatchingPos=(*isegEndcap)->globalPosition();
758 if((*isegBarrel)->localParameters().contains(
Trk::qOverP)){
759 p = ((*isegBarrel)->localParameters()[
Trk::qOverP]!=0.) ? fabs(1./((*isegBarrel)->localParameters()[
Trk::qOverP])) : 10e7;
763 if((*isegBarrel)->localParameters().contains(
Trk::phi)){
773 ATH_MSG_VERBOSE(
"Global position: "<<inputMatchingPos<<
" Globalmomentum: "<<inputMatchingMom);
778 Trk::MeasurementSet::const_iterator mit;
779 Trk::MeasurementSet::const_iterator mitE=myset.end();
782 for(mit=myset.begin();mit!=mitE;++mit){
783 myset2.push_back(*mit);
784 if(count2==firstechit || count2==lastechit){
792 if ((count2==firstechit && firstechit!=0) || (count2==lastechit && firstechit==0)) locz=200;
806 if(fabs(gpos.z())>800){
818 T = line->transform().rotation();
826 tobedeleted.push_back(pseudo);
830 myset2.push_back(pseudo);
840 if((*isegEndcap)->globalPosition().y()>0){
855 ATH_MSG_VERBOSE(
"Associated surface dynamic_cast into PerigeeSurface failed. "<<(*isegBarrel)->associatedSurface());
856 ATH_MSG_VERBOSE(
"Leaving input matching perigee as nullptr, will not get a fittedTrack");
859 inputMatchPerigee =
new Trk::Perigee(inputMatchingPos,inputMatchingMom, 1., *testPSf);
868 std::unique_ptr<Trk::Track> fittedTrack;
877 }
else if (inputMatchPerigee){
893 }
else if (inputMatchPerigee){
906 ATH_MSG_DEBUG(
"Quality of Track: "<<fittedTrack->fitQuality()->chiSquared()<<
" / "<<fittedTrack->fitQuality()->numberDoF());
908 outputCombiCollection->push_back(std::move(fittedTrack));
911 delete inputMatchPerigee;
912 delete inputMatchLine;
914 for(
size_t i=0;i<tobedeleted.size();i++)
915 delete tobedeleted[i];
922 if (!outputCombiCollection.
isValid()) {
923 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.
StatusCode execute(const EventContext &ctx)
Execute method.
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.