Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-29 07:05:22

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Whitney Armstrong
0003 
0004 #include <cmath>
0005 // Gaudi
0006 #include "Gaudi/Property.h"
0007 #include "GaudiAlg/GaudiAlgorithm.h"
0008 #include "GaudiAlg/GaudiTool.h"
0009 #include "GaudiAlg/Transformer.h"
0010 #include "GaudiKernel/ToolHandle.h"
0011 
0012 #include "JugBase/DataHandle.h"
0013 #include "JugBase/IGeoSvc.h"
0014 #include "JugTrack/ProtoTrack.hpp"
0015 #include "JugTrack/Track.hpp"
0016 
0017 #include "Math/Vector3D.h"
0018 
0019 #include "edm4eic/TrackerHitCollection.h"
0020 
0021 namespace Jug::Reco {
0022 
0023 /** Template finder.
0024  *
0025  *  \ingroup tracking
0026  */
0027 class ProtoTrackMatching : public GaudiAlgorithm {
0028 private:
0029   DataHandle<edm4eic::TrackerHitCollection> m_inputTrackerHits{"inputTrackerHits", Gaudi::DataHandle::Reader, this};
0030   DataHandle<TrackParametersContainer> m_initialTrackParameters{"initialTrackParameters", Gaudi::DataHandle::Reader, this};
0031   DataHandle<ProtoTrackContainer> m_inputProtoTracks{"inputProtoTracks", Gaudi::DataHandle::Reader, this};
0032   DataHandle<ProtoTrackContainer> m_outputProtoTracks{"matchedProtoTracks", Gaudi::DataHandle::Writer, this};
0033 
0034 public:
0035   ProtoTrackMatching(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {
0036     declareProperty("inputTrackerHits",     m_inputTrackerHits,     "");
0037     declareProperty("initialTrackParameters", m_initialTrackParameters, "");
0038     declareProperty("inputProtoTracks",       m_inputProtoTracks,       "");
0039     declareProperty("matchedProtoTracks",     m_outputProtoTracks, "proto tracks matched to initial track parameters");
0040   }
0041 
0042   StatusCode initialize() override {
0043     if (GaudiAlgorithm::initialize().isFailure()) {
0044       return StatusCode::FAILURE;
0045     }
0046     return StatusCode::SUCCESS;
0047   }
0048 
0049   StatusCode execute() override {
0050     // input collection
0051     
0052     // hits is unused, commented out for now to avoid compiler warning
0053     //const auto* const hits              = m_inputTrackerHits.get();
0054     
0055     const auto* const proto_tracks      = m_inputProtoTracks.get();
0056     const auto* const initialParameters = m_initialTrackParameters.get();
0057 
0058     // Create output collections
0059     auto* matched_proto_tracks = m_outputProtoTracks.createAndPut();
0060 
0061     int n_tracks = initialParameters->size();
0062     int n_proto_tracks = proto_tracks->size();
0063 
0064     // Assuming init track parameters have been match with proto tracks by index
0065     if(n_proto_tracks <  n_tracks) {
0066       warning() << " Number of proto tracks does not match the initial track parameters." << endmsg;
0067       if(n_proto_tracks == 0 ) {
0068         warning() << " Zero proto tracks to match! " << endmsg;
0069         return StatusCode::SUCCESS;
0070       }
0071     }
0072 
0073 
0074     if (msgLevel(MSG::DEBUG)) {
0075       debug() << " ntracks        " << n_tracks <<  endmsg;
0076       debug() << " n_proto_tracks " << n_proto_tracks <<  endmsg;
0077     }
0078     // do better matching
0079     for (int itrack = 0; itrack < n_tracks; itrack++) {
0080       // track_param and iproto_best currently unused, but will be in the future
0081       // commented out to remove compiler warning
0082       //const auto& track_param = (*initialParameters)[itrack];
0083       //int iproto_best = 0;
0084 
0085       /// \todo FIXME
0086       /// find the best matching proto track:
0087       /// here we just take the first.
0088       if( n_proto_tracks <= itrack) {
0089           matched_proto_tracks->push_back( proto_tracks->back() );
0090       } else {
0091           matched_proto_tracks->push_back( (*proto_tracks)[itrack] );
0092       }
0093       //for(const auto& aproto : (*protoTracks)){
0094       //  const auto& proto_track = (*protoTracks)[iproto];
0095       //  if(n_proto_tracks <  n_tracks) {
0096       //  }
0097       //}
0098     }
0099     return StatusCode::SUCCESS;
0100   }
0101 };
0102 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
0103 DECLARE_COMPONENT(ProtoTrackMatching)
0104 
0105 } // namespace Jug::Reco