15 #include "GaudiKernel/MsgStream.h"
39 (
const std::string&
name, ISvcLocator* pSvcLocator)
41 m_trackmaker(
"InDet::TRT_SeededTrackFinderTool"),
42 m_fitterTool(
"Trk::GlobalChi2Fitter/InDetTrackFitter"),
43 m_SegmentsKey(
"TRTSegments"),
44 m_outTracksKey(
"TRTSeededTracks")
123 return StatusCode::SUCCESS;
138 if (!
key.key().empty()) {
160 ATH_MSG_FATAL (
"No segment with name " << segments.
name() <<
" found in StoreGate!");
161 return StatusCode::FAILURE;
163 ATH_MSG_DEBUG (
"Found segments collection " << segments.
name() <<
" in StoreGate!");
169 ATH_MSG_DEBUG (
"TRT track container size huge; will process event partially if number of max segments reached !!!");
173 std::unique_ptr<InDet::ITRT_SeededTrackFinder::IEventData> event_data_p;
176 std::unique_ptr<RoiDescriptor> roiComp = std::make_unique<RoiDescriptor>(
true);
180 double beamZ = beamSpotHandle->beamVtx().position().z();
183 for (
const ROIPhiRZ &the_roi : *calo_rois) {
184 double eta = the_roi.eta();
185 double phi = the_roi.phi();
192 roi =
new RoiDescriptor(
eta, roiEtaMin, roiEtaMax,
phi, roiPhiMin ,roiPhiMax, beamZ, roiZMin,roiZMax);
197 std::vector<IdentifierHash> listOfSCTIds;
198 std::vector<IdentifierHash> listOfPixIds;
200 event_data_p =
m_trackmaker->newRegion(ctx, combinatorialData, listOfPixIds, listOfSCTIds);
202 event_data_p =
m_trackmaker->newEvent(ctx, combinatorialData);
205 std::unique_ptr<InDet::ITRT_TrackExtensionTool::IEventData> ext_event_data_p(
m_trtExtension->newEvent(ctx) );
206 std::unique_ptr<TrackCollection> outTracks = std::make_unique<TrackCollection>();
207 std::vector<Trk::Track*> tempTracks;
208 tempTracks.reserve(128);
210 ATH_MSG_DEBUG (
"Begin looping over all TRT segments in the event");
214 for(; iseg != isegEnd; ++ iseg) {
231 ATH_MSG_DEBUG (
"====> Reached maximal number of segments in event, stop !!!");
239 ev_stat.
m_counter[Stat_t::Stat_t::kNTrtSegGood]++;
241 std::list<Trk::Track*> trackSi =
m_trackmaker->getTrack(ctx, *event_data_p, *trackTRT);
242 if (trackSi.empty()) {
243 ATH_MSG_DEBUG (
"No Si track candidates associated to the TRT track ");
251 ATH_MSG_DEBUG (
"Failed to make a track out of the TRT segment!");
257 outTracks->push_back(trtSeg);
262 ATH_MSG_DEBUG (
"Found " << (trackSi.size()) <<
" Si tracks associated to the TRT track ");
264 std::list<Trk::Track*>::const_iterator itt = trackSi.begin();
265 std::list<Trk::Track*>::const_iterator ittEnd = trackSi.end();
266 for (; itt != ittEnd ; ++itt){
267 tempTracks.push_back(*itt);
279 auto input = (*itt)->trackParameters()->front()->uniqueClone();
297 beamSpotPosition = beamSpotHandle->beamVtx().position();
303 std::unique_ptr<const Trk::TrackParameters> parm =
305 ctx, *
input, perigeeSurface);
306 std::unique_ptr<const Trk::Perigee> extrapolatedPerigee =
nullptr;
308 extrapolatedPerigee.reset(
static_cast<const Trk::Perigee*
>(parm.release()));
310 if (!extrapolatedPerigee) {
311 ATH_MSG_WARNING(
"Extrapolation of perigee failed, this should never happen" );
337 ATH_MSG_DEBUG (
"Try to improve TRT calling extension tool.");
339 ev_stat.
m_counter[Stat_t::Stat_t::kNTrtExtCalls]++;
341 std::vector<const Trk::MeasurementBase*>& tn =
342 m_trtExtension->extendTrack(ctx, *(*itt), *ext_event_data_p, map);
345 ATH_MSG_DEBUG (
"No new segment found, use input segment as fallback.");
347 ev_stat.
m_counter[Stat_t::Stat_t::kNTrtExtFail]++;
361 std::vector<const Trk::MeasurementBase*>::const_iterator iv, ive=tn.end();
362 for(iv=tn.begin(); iv!=ive; ++iv)
delete (*iv);
371 ev_stat.
m_counter[Stat_t::Stat_t::kNTrtExtBad]++;
373 std::vector<const Trk::MeasurementBase*>::const_iterator iv, ive=tn.end();
374 for(iv=tn.begin(); iv!=ive; ++iv)
delete (*iv);
378 ATH_MSG_DEBUG (
"Do not try to extend Si track, merging it with input TRT.");
388 ATH_MSG_DEBUG (
"Failed to make a track out of the TRT segment!");
399 outTracks->push_back(trtSeg);
410 outTracks->push_back(globalTrackNew);
423 return StatusCode::FAILURE;
427 std::lock_guard<std::mutex> lock(m_statMutex);
428 m_totalStat += ev_stat;
431 for (
auto *
p : tempTracks){
441 return StatusCode::SUCCESS;
451 msg(MSG::INFO) <<
"\n";
455 return StatusCode::SUCCESS;
466 std::string s1;
for(
int i=0;
i<
n; ++
i) s1.append(
" "); s1.append(
"|");
468 std::string
s2;
for(
int i=0;
i<
n; ++
i)
s2.append(
" ");
s2.append(
"|");
470 std::string
s3;
for(
int i=0;
i<
n; ++
i)
s3.append(
" ");
s3.append(
"|");
472 std::string
s4;
for(
int i=0;
i<
n; ++
i)
s4.append(
" ");
s4.append(
"|");
474 std::string s5;
for(
int i=0;
i<
n; ++
i) s5.append(
" "); s5.append(
"|");
476 out<<
"|----------------------------------------------------------------------"
477 <<
"-------------------|"
479 out<<
"| Tool for TRT seeded track finding | "<<
m_trackmaker.type() <<s1<<std::endl;
484 out<<
"|----------------------------------------------------------------------"
485 <<
"-------------------|"
496 out<<
"|-------------------------------------------------------------------"<<std::endl;
497 out<<
"| Investigated :"<<std::endl
500 <<
"| "<<std::setw(7)<<
stat.m_counter[Stat_t::Stat_t::kNTrtSegGood] <<
" TRT Segments after selection"<<std::endl;
502 out<<
"|-------------------------------------------------------------------"<<std::endl;
503 out<<
"| "<<std::setw(7)<<
stat.m_counter[
Stat_t::kNTrtLimit] <<
" TRT segments lost because of processing limit"<<std::endl;
505 out<<
"|-------------------------------------------------------------------"<<std::endl;
510 if (
stat.m_counter[Stat_t::Stat_t::kNBckTrkTrt]>0) {
511 out<<
"| "<<std::setw(7)<<
stat.m_counter[Stat_t::Stat_t::kNBckTrkTrt] <<
" number ot TRT only tracks created"<<std::endl;
514 out<<
"|-------------------------------------------------------------------"<<std::endl;
515 out<<
"| "<<std::setw(7)<<
stat.m_counter[Stat_t::Stat_t::kNTrtExtCalls]<<
" number of times TRT extension is called"<<std::endl
516 <<
"| "<<std::setw(7)<<
stat.m_counter[
Stat_t::kNTrtExt] <<
" number of good TRT extension"<<std::endl;
518 out<<
"| "<<std::setw(7)<<
stat.m_counter[Stat_t::Stat_t::kNTrtExtBad]<<
" number of bad TRT extension"<<std::endl;
520 out<<
"| "<<std::setw(7)<<
stat.m_counter[Stat_t::Stat_t::kNTrtExtFail]<<
" number of failed TRT extension and fallback"<<std::endl;
522 out<<
"|-------------------------------------------------------------------"<<std::endl;
523 out<<
"| "<<std::setw(7)<<
stat.m_counter[Stat_t::Stat_t::kNBckTrkSi] <<
" TRT+Si tracks created of output"<<std::endl;
527 out<<
"|-------------------------------------------------------------------";
542 auto ntsos = std::make_unique<Trk::TrackStates>();
546 for (p_stsos=stsos->
begin(); p_stsos != stsos->
end(); ++p_stsos) {
547 ntsos->push_back( (*p_stsos)->clone() );
555 ATH_MSG_DEBUG (
"Too few Si hits.Will keep pseudomeasurement...");
557 ntsos->push_back(seg_tsos);
560 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
563 ntsos->push_back(seg_tsos);
570 std::unique_ptr<Trk::Track> newTrack(std::make_unique<Trk::Track>(
info, std::move(ntsos), std::move(fq)));
582 if (!CM || std::sqrt((*CM)(1,1)) == 0. || std::sqrt((*CM)(3,3)) == 0.) {
587 return newTrack.release();
595 ATH_MSG_DEBUG (
"Transforming the TRT segment into a track...");
600 throw std::logic_error(
"Unhandled surface.");
604 auto ntsos = std::make_unique<Trk::TrackStates>();
605 std::unique_ptr<Trk::TrackParameters> segPar =
607 p(0),
p(1),
p(2),
p(3),
p(4), std::move(ep));
609 ATH_MSG_DEBUG(
"Initial TRT Segment Parameters for refitting " << (*segPar) );
611 ATH_MSG_DEBUG(
"Could not get initial TRT segment parameters! " );
617 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
624 ntsos->push_back(seg_tsos);
628 std::unique_ptr<Trk::Track> newTrack = std::make_unique<Trk::Track>(
info, std::move(ntsos),
nullptr);
640 if (!CM || std::sqrt((*CM)(1,1)) == 0. || std::sqrt((*CM)(3,3)) == 0.) {
645 return newTrack.release();
659 auto ntsos = std::make_unique<Trk::TrackStates>();
662 for (p_stsos = stsos->
begin(); p_stsos != stsos->
end(); ++p_stsos) {
663 ntsos->push_back((*p_stsos)->clone());
666 for (
auto &
it : tS) {
667 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
670 ntsos->push_back(seg_tsos);
675 std::unique_ptr<Trk::Track> newTrack( std::make_unique<Trk::Track>(
info, std::move(ntsos), std::move(fq)) );
687 if (!CM || std::sqrt((*CM)(1,1)) == 0. || std::sqrt((*CM)(3,3)) == 0.) {
693 return newTrack.release();
705 int nsct1{}, nsct2{}, nsct3{}, nsct4{};
706 int nsctTot1{}, nsctTot2{}, nsctTot3{}, nsctTot4{};
707 int npix1{}, npix2{}, npix3{};
708 int npixTot1{}, npixTot2{}, npixTot3{};
712 for (;
r !=
re ; ++
r){
713 nsct1=nsct2=nsct3=nsct4=0; npix1=npix2=npix3=0;
715 if(!newtsos)
continue;
722 if((40.<=rc)&&(rc<80.)){npix1++;}
723 if((80.<=rc)&&(rc<100.)){npix2++;}
724 if((100.<=rc)&&(rc<150.)){npix3++;}
725 if((280.<=rc)&&(rc<340.)){nsct1++;}
726 if((340.<=rc)&&(rc<390.)){nsct2++;}
727 if((390.<=rc)&&(rc<460.)){nsct3++;}
728 if((460.<=rc)&&(rc<550.)){nsct4++;}
731 nsctTot1+=nsct1; nsctTot2+=nsct2; nsctTot3+=nsct3; nsctTot4+=nsct4;
732 npixTot1+=npix1; npixTot2+=npix2; npixTot3+=npix3;
734 ATH_MSG_DEBUG(
"Total hits on 1st SCT: "<<nsctTot1<<
" 2nd SCT: "<<nsctTot2<<
" 3rd SCT: "<<nsctTot3<<
" 4th SCT: "<<nsctTot4);
735 ATH_MSG_DEBUG(
"Total hits on 1st Pixel: "<<npixTot1<<
" 2nd Pixel: "<<npixTot2<<
" 3rd Pixel: "<<npixTot3);