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();
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");
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);
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>();
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()};
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),
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());
342 int nhits=(*iseg)->numberOfMeasurementBases();
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) {
407 for (std::unique_ptr<Trk::Track> &
track : output_track_collection) {
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());
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){
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");