diff --git a/Core/include/Acts/Seeding/GNN_DataStorage.hpp b/Core/include/Acts/Seeding/GNN_DataStorage.hpp index b51fd477bb8..a30065c87f0 100644 --- a/Core/include/Acts/Seeding/GNN_DataStorage.hpp +++ b/Core/include/Acts/Seeding/GNN_DataStorage.hpp @@ -68,12 +68,12 @@ class TrigFTF_GNN_EtaBin { TrigFTF_GNN_EtaBin() { m_vn.clear(); } - // ~TrigFTF_GNN_EtaBin(); + ~TrigFTF_GNN_EtaBin() { // for(std::vector*>::iterator it = m_vn.begin();it!=m_vn.end();++it) { - for(auto i : m_vn){ - delete (&i); - } + // for(auto i : m_vn){ + // delete (&i); + // } m_vn.clear(); } diff --git a/Core/include/Acts/Seeding/GNN_Geometry.hpp b/Core/include/Acts/Seeding/GNN_Geometry.hpp index 6c0939727db..f083e2c14c9 100644 --- a/Core/include/Acts/Seeding/GNN_Geometry.hpp +++ b/Core/include/Acts/Seeding/GNN_Geometry.hpp @@ -7,17 +7,19 @@ namespace Acts { class TrigInDetSiLayer { public: - int m_subdet;//1 : Pixel, 2 : SCT + int m_subdet;//combined ID int m_type;//0: barrel, +/-n : endcap float m_refCoord; float m_minBound, m_maxBound; + + TrigInDetSiLayer(int subdet, short int type, float center, float min, float max ) : m_subdet(subdet), m_type(type), m_refCoord(center), m_minBound(min), m_maxBound(max) { + + } }; template class TrigFTF_GNN_Layer { public: - // TrigFTF_GNN_Layer(const TrigInDetSiLayer&, float, int); - TrigFTF_GNN_Layer(const TrigInDetSiLayer& ls, float ew, int bin0) : m_layer(ls), m_etaBinWidth(ew) { @@ -130,10 +132,9 @@ class TrigFTF_GNN_Layer { } } - // ~TrigFTF_GNN_Layer(); - ~TrigFTF_GNN_Layer() { - m_bins.clear(); - } + // ~TrigFTF_GNN_Layer() { + // m_bins.clear(); + // } // int getEtaBin(float, float) const; int getEtaBin(float zh, float rh) const { @@ -233,7 +234,8 @@ class TrigFTF_GNN_Layer { } - const TrigInDetSiLayer& m_layer; + // const TrigInDetSiLayer& m_layer; + const TrigInDetSiLayer m_layer; //CHECK: changed from ref to copy for saftey std::vector m_bins;//eta-bin indices std::vector m_minRadius; std::vector m_maxRadius; @@ -263,10 +265,12 @@ class TrigFTF_GNN_Geometry { const float max_z0 = 168.0; m_etaBinWidth = conn->m_etaBin; - for(const auto& layer : layers) { const TrigFTF_GNN_Layer* pL = addNewLayer(layer, m_nEtaBins); m_nEtaBins += pL->num_bins(); + // std::cout << " Rosie printing layer vector " << layer.m_subdet << std::endl; + + } //calculating bin tables in the connector... @@ -279,7 +283,7 @@ class TrigFTF_GNN_Geometry { unsigned int src = (*cIt)->m_src;//n2 : the new connectors unsigned int dst = (*cIt)->m_dst;//n1 - + const TrigFTF_GNN_Layer* pL1 = getTrigFTF_GNN_LayerByKey(dst); const TrigFTF_GNN_Layer* pL2 = getTrigFTF_GNN_LayerByKey(src); @@ -311,29 +315,35 @@ class TrigFTF_GNN_Geometry { TrigFTF_GNN_Geometry() : m_nEtaBins(0) { } - // ~TrigFTF_GNN_Geometry(); ~TrigFTF_GNN_Geometry() { - for(auto& i : m_layArray) { - // for(std::vector*>::iterator it = m_layArray.begin();it!=m_layArray.end();++it) { - delete (&i); + std::cout << "start of gnn geo's destructor " << std::endl ; + + + + for(typename std::vector*>::iterator it = m_layArray.begin();it!=m_layArray.end();++it) { + delete (*it); } + + std::cout << "middle of gnn geo's destructor " << std::endl ; + m_layMap.clear();m_layArray.clear(); + std::cout << "end of gnn geo's destructor " << std::endl ; + } - - // const TrigFTF_GNN_Layer* getTrigFTF_GNN_LayerByKey(unsigned int) const; - const TrigFTF_GNN_Layer* getTrigFTF_GNN_LayerByKey(unsigned int key) const { typename std::map*>::const_iterator it = m_layMap.find(key); if(it == m_layMap.end()) { + // std::cout << "Rosie, printing map info" << m_layMap.size() << std::endl ; + return nullptr; } - return (*it).second; - } + - // const TrigFTF_GNN_Layer* getTrigFTF_GNN_LayerByIndex(int) const; + return (*it).second; + } const TrigFTF_GNN_Layer* getTrigFTF_GNN_LayerByIndex(int idx) const { return m_layArray.at(idx); @@ -343,12 +353,10 @@ class TrigFTF_GNN_Geometry { protected: - // const TrigFTF_GNN_Layer* addNewLayer(const TrigInDetSiLayer&, int); - const TrigFTF_GNN_Layer* addNewLayer(const TrigInDetSiLayer& l, int bin0) { - unsigned int layerKey = l.m_subdet; - + unsigned int layerKey = l.m_subdet; //this should be combined ID + // std::cout << " Rosie seeing what key values are " << layerKey << std::endl; float ew = m_etaBinWidth; TrigFTF_GNN_Layer* pHL = new TrigFTF_GNN_Layer(l, ew, bin0); diff --git a/Core/include/Acts/Seeding/SeedFinderFTF.hpp b/Core/include/Acts/Seeding/SeedFinderFTF.hpp index d5a2a21e0e6..91c84228d70 100644 --- a/Core/include/Acts/Seeding/SeedFinderFTF.hpp +++ b/Core/include/Acts/Seeding/SeedFinderFTF.hpp @@ -8,7 +8,7 @@ #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SeedFinderFTFConfig.hpp" #include "Acts/Utilities/KDTree.hpp" -#include "Acts/Seeding/GNN_DataStorage.hpp" +// #include "Acts/Seeding/GNN_DataStorage.hpp" #include diff --git a/Core/include/Acts/Seeding/SeedFinderFTF.ipp b/Core/include/Acts/Seeding/SeedFinderFTF.ipp index 1142709b64c..754afc901ea 100644 --- a/Core/include/Acts/Seeding/SeedFinderFTF.ipp +++ b/Core/include/Acts/Seeding/SeedFinderFTF.ipp @@ -34,20 +34,34 @@ SeedFinderFTF::SeedFinderFTF( // "SeedFinderOrthogonalConfig not in ACTS internal units in " // "SeedFinderOrthogonal"); + std::cout << "in FTF finder constructor 1 " << std::endl ; - std::vector input_vector ; std::ifstream input_ifstream(m_config.fastrack_input_file.c_str(), std::ifstream::in) ; + std::cout << "in FTF finder constructor 2 " << std::endl ; + FasTrackConnector input_fastrack(input_ifstream) ; - TrigFTF_GNN_Geometry mGNNgeo(input_vector, &input_fastrack); + std::cout << "in FTF finder constructor 3" << std::endl ; + + TrigFTF_GNN_Geometry mGNNgeo(m_config.input_vector, &input_fastrack); + std::cout << "in FTF finder constructor 4 " << std::endl ; + m_storage = new TrigFTF_GNN_DataStorage(mGNNgeo); + std::cout << "in FTF finder constructor 5 " << std::endl ; + } template SeedFinderFTF::~SeedFinderFTF(){ + std::cout << "in FTF finder destructor 1 " << std::endl ; + delete m_storage ; + std::cout << "in FTF finder destructor 2 " << std::endl ; + m_storage = nullptr ; + std::cout << "in FTF finder destructor 3 " << std::endl ; + } @@ -55,19 +69,24 @@ SeedFinderFTF::~SeedFinderFTF(){ //when calling put input of vector, now can call space_point_t template void SeedFinderFTF::loadSpacePoints(const std::vector>& FTF_SP_vect){ + std::cout << "in lsp 1" << std::endl ; + + // for(auto& FTF_sp : FTF_SP_vect) { + // bool is_Pixel = FTF_sp.SP->isPixel(); //FTF actual object then sim is pointer + // if(!is_Pixel) continue; + + // m_storage->addSpacePoint(FTF_sp,(m_config.m_useTrigSeedML > 0) ); //add is a funciton FTFtype - for(auto& FTF_sp : FTF_SP_vect) { - bool is_Pixel = FTF_sp.SP->isPixel(); //FTF actual object then sim is pointer - if(!is_Pixel) continue; + // } + // std::cout << "in lsp 2 " << std::endl ; - m_storage->addSpacePoint(FTF_sp,(m_config.m_useTrigSeedML > 0) ); //add is a funciton FTFtype - } + // m_config.m_phiSliceWidth = 2*M_PI/m_config.m_nMaxPhiSlice; - m_config.m_phiSliceWidth = 2*M_PI/m_config.m_nMaxPhiSlice; + // m_storage->sortByPhi(); + // m_storage->generatePhiIndexing(1.5*m_config.m_phiSliceWidth); - m_storage->sortByPhi(); - m_storage->generatePhiIndexing(1.5*m_config.m_phiSliceWidth); + std::cout << "end of lsp " << std::endl ; } diff --git a/Core/include/Acts/Seeding/SeedFinderFTFConfig.hpp b/Core/include/Acts/Seeding/SeedFinderFTFConfig.hpp index 978034491e2..393f57a1c6d 100644 --- a/Core/include/Acts/Seeding/SeedFinderFTFConfig.hpp +++ b/Core/include/Acts/Seeding/SeedFinderFTFConfig.hpp @@ -4,6 +4,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Units.hpp" #include "Acts/Seeding/SeedConfirmationRangeConfig.hpp" +#include "Acts/Seeding/GNN_DataStorage.hpp" #include @@ -106,6 +107,7 @@ struct SeedFinderFTFConfig { float m_nMaxPhiSlice ; bool m_useTrigSeedML = false ; std::string fastrack_input_file ; + std::vector input_vector ; //// diff --git a/Core/src/TrackFinding/FasTrackConnector.cpp b/Core/src/TrackFinding/FasTrackConnector.cpp index 08ed5ceea2f..7b30bae509f 100644 --- a/Core/src/TrackFinding/FasTrackConnector.cpp +++ b/Core/src/TrackFinding/FasTrackConnector.cpp @@ -59,6 +59,8 @@ FasTrackConnector::FasTrackConnector(std::ifstream& inFile) { } FasTrackConnector::~FasTrackConnector() { + std::cout << "start of fastrack destructor " << std::endl ; + for(std::map >::iterator it = m_connMap.begin();it!=m_connMap.end();++it) { for(std::vector::iterator cIt=(*it).second.begin();cIt!=(*it).second.end();++cIt) { delete (*cIt); @@ -66,6 +68,8 @@ FasTrackConnector::~FasTrackConnector() { (*it).second.clear(); } m_connMap.clear(); + std::cout << "end of fastrack destructor " << std::endl ; + } } \ No newline at end of file diff --git a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingFTFAlgorithm.hpp b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingFTFAlgorithm.hpp index 10c9881a52e..c2f1004d54c 100644 --- a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingFTFAlgorithm.hpp +++ b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingFTFAlgorithm.hpp @@ -14,6 +14,7 @@ #include "ActsExamples/EventData/SimSpacePoint.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IAlgorithm.hpp" +#include "Acts/Geometry/TrackingGeometry.hpp" #include #include @@ -34,6 +35,14 @@ class SeedingFTFAlgorithm final : public IAlgorithm { std::string layerMappingFile ; + std::vector geometrySelection; + + std::string inputSourceLinks; + + std::shared_ptr trackingGeometry; + + std::map,std::pair> ACTS_FTF_Map ; + }; @@ -50,6 +59,15 @@ class SeedingFTFAlgorithm final : public IAlgorithm { //access to config const Config& config() const { return m_cfg; } + //own class functions + //make the map + std::map,std::pair> Make_ACTS_FTF_Map() const ; + //make the vector of space points with FTF Info + std::vector> Make_FTF_spacePoints(const AlgorithmContext& ctx, std::map,std::pair> map) const; + //layer numbering + // std::vector LayerNumbering(const AlgorithmContext& ctx, std::map,int> map) const ; + + std::vector LayerNumbering() const ; private: Config m_cfg; @@ -59,6 +77,11 @@ class SeedingFTFAlgorithm final : public IAlgorithm { m_inputSpacePoints{}; WriteDataHandle m_outputSeeds{this, "OutputSeeds"}; + + ReadDataHandle m_inputSourceLinks{ + this, "InputSourceLinks"}; + + }; } // namespace ActsExamples \ No newline at end of file diff --git a/Examples/Algorithms/TrackFinding/src/LayerNumbering.cpp b/Examples/Algorithms/TrackFinding/src/LayerNumbering.cpp new file mode 100644 index 00000000000..de45c2b4ebd --- /dev/null +++ b/Examples/Algorithms/TrackFinding/src/LayerNumbering.cpp @@ -0,0 +1,58 @@ + +void ActsExamples::FillInputVector(ActsExamples::SeedingFTFAlgorithm::Config cfg) m_cfg(std::move(cfg)) { + ///////Hough code /////////// + ///(sourceLinks = m_cfg.inputSourceLinks) + ///const auto& measurements = m_inputMeasurements(ctx); + for (Acts::GeometryIdentifier geoId : m_cfg.geometrySelection) { + // select volume/layer depending on what is set in the geometry id + + auto range = selectLowestNonZeroGeometryObject(sourceLinks, geoId); + + auto groupedByModule = makeGroupBy(range, detail::GeometryIdGetter()); /// Iterate over groups of elements belonging to each module/ sensitive surface. + + for (auto [moduleGeoId, moduleSourceLinks] : groupedByModule) { + // find corresponding surface + const Acts::Surface* surface = + m_cfg.trackingGeometry->findSurface(moduleGeoId); + if (surface == nullptr) { + ACTS_ERROR("Could not find surface " << moduleGeoId); + return; + } + + for (auto& sourceLink : moduleSourceLinks) { + + auto [localPos, localCov] = std::visit( + [](const auto& meas) { + auto expander = meas.expander(); + Acts::BoundVector par = expander * meas.parameters(); + Acts::BoundSymMatrix cov = + expander * meas.covariance() * expander.transpose(); + // extract local position + Acts::Vector2 lpar(par[Acts::eBoundLoc0], par[Acts::eBoundLoc1]); + // extract local position covariance. + Acts::SymMatrix2 lcov = + cov.block<2, 2>(Acts::eBoundLoc0, Acts::eBoundLoc0); + return std::make_pair(lpar, lcov); + }, + measurements[sourceLink.index()]); + + // transform local position to global coordinates + Acts::Vector3 globalFakeMom(1, 1, 1); + Acts::Vector3 globalPos = surface->localToGlobal(ctx.geoContext, localPos, globalFakeMom); //is this the center? + + + double r = std::hypot(globalPos[Acts::ePos0], globalPos[Acts::ePos1]); + double phi = std::atan2(globalPos[Acts::ePos1], globalPos[Acts::ePos0]); + double z = globalPos[Acts::ePos2]; + ResultUnsigned hitlayer = m_cfg.layerIDFinder(r); //is this the layer ACTS layer?? (.value()) //cant find where this is defined + if (hitlayer.ok()) { + std::vector index; + index.push_back(sourceLink.index()); + auto meas = std::shared_ptr( + new HoughMeasurementStruct(hitlayer.value(), phi, r, z, index, HoughHitType::MEASUREMENT)); + houghMeasurementStructs.push_back(meas); + } + } + } + } +} diff --git a/Examples/Algorithms/TrackFinding/src/SeedingFTFAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingFTFAlgorithm.cpp index f1f9ec497ed..dc10a6fa1b5 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingFTFAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingFTFAlgorithm.cpp @@ -7,12 +7,17 @@ #include "ActsExamples/EventData/ProtoTrack.hpp" #include "ActsExamples/EventData/SimSeed.hpp" #include "ActsExamples/Framework/WhiteBoard.hpp" +//might need for layer numbering funciton +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "ActsExamples/EventData/Measurement.hpp" #include #include #include #include #include +#include + using namespace std; @@ -30,49 +35,147 @@ ActsExamples::SeedingFTFAlgorithm::SeedingFTFAlgorithm( Acts::Logging::Level lvl) : ActsExamples::IAlgorithm("SeedingAlgorithm", lvl), m_cfg(std::move(cfg)) { + + std::cout << "in initialise 1" << std::endl ; //fill config struct m_cfg.layerMappingFile = m_cfg.layerMappingFile ; + std::cout << "in initialise 2 " << std::endl ; m_cfg.seedFilterConfig = m_cfg.seedFilterConfig.toInternalUnits(); + std::cout << "in initialise 3 " << std::endl ; m_cfg.seedFinderConfig = m_cfg.seedFinderConfig.toInternalUnits().calculateDerivedQuantities(); + std::cout << "in initialise 4 " << std::endl ; m_cfg.seedFinderOptions = m_cfg.seedFinderOptions.toInternalUnits().calculateDerivedQuantities( m_cfg.seedFinderConfig); + std::cout << "in initialise 5 " << std::endl ; + + + m_cfg.ACTS_FTF_Map = Make_ACTS_FTF_Map() ; + std::cout << "in initialise 6 " << std::endl ; - for (const auto &spName : m_cfg.inputSpacePoints) { - if (spName.empty()) { - throw std::invalid_argument("Invalid space point input collection"); - } + m_cfg.seedFinderConfig.input_vector = LayerNumbering() ; + std::cout << "in initialise 7 " << std::endl ; - auto &handle = m_inputSpacePoints.emplace_back( - std::make_unique>( - this, - "InputSpacePoints#" + std::to_string(m_inputSpacePoints.size()))); - handle->initialize(spName); - } + + for (const auto &spName : m_cfg.inputSpacePoints) { + if (spName.empty()) { + throw std::invalid_argument("Invalid space point input collection"); + } + + auto &handle = m_inputSpacePoints.emplace_back( + std::make_unique>( + this, + "InputSpacePoints#" + std::to_string(m_inputSpacePoints.size()))); + handle->initialize(spName); + } + std::cout << "in initialise 8 " << std::endl ; m_outputSeeds.initialize(m_cfg.outputSeeds); + std::cout << "in initialise 9 " << std::endl ; + + + m_inputSourceLinks.initialize(m_cfg.inputSourceLinks); + std::cout << "in initialise 9 " << std::endl ; + m_cfg.seedFinderConfig.seedFilter = std::make_unique>( Acts::SeedFilter(m_cfg.seedFilterConfig)); + std::cout << "in initialise 10 " << std::endl ; + //this is now calling to a core algorithm + if (&m_cfg.seedFinderConfig == nullptr){ + + std::cout << "config is empty " << std::endl ; + + } + else{ + std::cout << "config is fine" << std::endl ; + + } m_seedFinder = Acts::SeedFinderFTF(m_cfg.seedFinderConfig); + std::cout << "in initialise 11 " << std::endl ; + } //this is not FTF config type because it is a meber of the algs config, which is of type FTF cofig + + //exectute: ActsExamples::ProcessCode ActsExamples::SeedingFTFAlgorithm::execute( const AlgorithmContext& ctx) const { + std::cout << "in execute 1 " << std::endl ; + + std::vector> FTF_spacePoints = Make_FTF_spacePoints(ctx, m_cfg.ACTS_FTF_Map); + + + // //loop over FTF_SP vector to plot the space points + // fstream fout; + // fout.open("FTF_SP_output.csv", ios::out | ios::app); + // for (auto sp : FTF_spacePoints){ + // fout << sp.FTF_ID << ", " + // << sp.SP->z() << ", " + // << sp.SP->r() + // << "\n"; + // } + std::cout << "in execute 2 " << std::endl ; + + + for (auto sp : FTF_spacePoints){ + ACTS_DEBUG("FTF space points: " << " FTF_id: "<< sp.FTF_ID << " z: " + << sp.SP->z() << " r: " << sp.SP->r() << " ACTS volume: " + << sp.SP->sourceLinks().front().geometryId().volume() << "\n"); + } + + std::cout << "in execute 3 " << std::endl ; + + + //this is now calling on a core algorithm + Acts::SeedFinderFTF finder(m_cfg.seedFinderConfig); + std::cout << "in execute 4 " << std::endl ; + + //need this function as create_coords is needed for seeds + std::function( + const SimSpacePoint *sp)> + create_coordinates = [](const SimSpacePoint *sp) { + Acts::Vector3 position(sp->x(), sp->y(), sp->z()); + Acts::Vector2 variance(sp->varianceR(), sp->varianceZ()); + return std::make_pair(position, variance); + }; + //output of function needed for seed + std::cout << "in execute 5 " << std::endl ; + + + finder.loadSpacePoints(FTF_spacePoints); + std::cout << "in execute 6 " << std::endl ; + + + //still to develop, input will be FTF_spacePoints + SimSeedContainer seeds = finder.createSeeds(m_cfg.seedFinderOptions, + FTF_spacePoints, create_coordinates); + + std::cout << "in execute 7 " << std::endl ; + + + m_outputSeeds(ctx, std::move(seeds)); + + + return ActsExamples::ProcessCode::SUCCESS; +} - //create map from csv - map,int> ACTS_FTF; + +std::map,std::pair> ActsExamples::SeedingFTFAlgorithm::Make_ACTS_FTF_Map() const { + + //create map from csv + // map,int> ACTS_FTF; + map,std::pair> ACTS_FTF; std::ifstream data(m_cfg.layerMappingFile); //0 in this file refers to no FTF ID std::string line; std::vector > parsedCsv; @@ -89,22 +192,32 @@ ActsExamples::ProcessCode ActsExamples::SeedingFTFAlgorithm::execute( parsedCsv.push_back(parsedRow); } - + // file in format ACTS_vol,ACTS_lay,ACTS_mod,FTF_id for (auto i : parsedCsv){ - int FTF = stoi(i[0]); - int ACTS_vol = stoi(i[1]); - int ACTS_lay = stoi(i[2]); - ACTS_FTF.insert({{ACTS_vol,ACTS_lay},FTF}) ; + int ACTS_vol = stoi(i[0]); + int ACTS_lay = stoi(i[1]); + int ACTS_mod = stoi(i[2]); + int FTF = stoi(i[5]); + int eta_mod = stoi(i[6]); + int ACTS_joint = ACTS_vol*100 + ACTS_lay ; + // ACTS_FTF.insert({{ACTS_joint,ACTS_mod},FTF}) ; + ACTS_FTF.insert({{ACTS_joint,ACTS_mod},{FTF,eta_mod}}) ; + //here think should have pair of new number, vol*100+layer, mod which is 0 or number } + return ACTS_FTF ; - //create space point vectors - std::vector spacePoints; - std::vector> FTF_spacePoints; +} + +std::vector> ActsExamples::SeedingFTFAlgorithm::Make_FTF_spacePoints(const AlgorithmContext& ctx, std::map,std::pair> map) const { + + //create space point vectors + std::vector spacePoints; + std::vector> FTF_spacePoints ; FTF_spacePoints.reserve(m_inputSpacePoints.size()); //not sure if this is enough, each one has several sp -//for loop filling space + //for loop filling space for (const auto &isp : m_inputSpacePoints) { for (const auto &spacePoint : (*isp)(ctx)) { //fill originial space point vector @@ -122,22 +235,34 @@ ActsExamples::ProcessCode ActsExamples::SeedingFTFAlgorithm::execute( int ACTS_vol_id = source_link.front().geometryId().volume() ; int ACTS_lay_id = source_link.front().geometryId().layer() ; - auto key = std::make_pair(ACTS_vol_id,ACTS_lay_id) ; - auto Find = ACTS_FTF.find(key) ; - - //dont want strips or HGTD, at the moment never called so commented out - // if (ACTS_vol_id == 2 or ACTS_vol_id == 22 or ACTS_vol_id == 23 or ACTS_vol_id == 24){ - // continue; - // } + int ACTS_mod_id = source_link.front().geometryId().sensitive() ; + //dont want strips or HGTD, at the moment never called so commented out + if (ACTS_vol_id == 2 or ACTS_vol_id == 22 or ACTS_vol_id == 23 or ACTS_vol_id == 24){ + continue; + } + + // Search for vol, lay 0n if doesnt esist (end) then search for full thing + //vol*100+lay as first number in pair then 0 or mod id + auto ACTS_joint_id = ACTS_vol_id*100 + ACTS_lay_id ; + auto key = std::make_pair(ACTS_joint_id,0) ; //here the key needs to be pair of(vol*100+lay, 0) + auto Find = map.find(key) ; + + if (Find == map.end()){ //if end then make new key of (vol*100+lay, modid) + key = std::make_pair(ACTS_joint_id,ACTS_mod_id) ; //mod ID + Find = map.find(key) ; + } + //warning if key not in map - if (Find == ACTS_FTF.end()){ + if (Find == map.end()){ ACTS_WARNING("Key not found in FTF map for volume id: " << ACTS_vol_id << " and layer id: " << ACTS_lay_id ); continue; } //now should be pixel with FTF ID: - int FTF_id = Find->second ; + // int FTF_id = Find->second ; + int FTF_id = Find->second.first ; //new map the item is a pair so want first from it + //backup warning shouldnt need as no 0 in csv if (FTF_id == 0) { @@ -152,34 +277,172 @@ ActsExamples::ProcessCode ActsExamples::SeedingFTFAlgorithm::execute( ACTS_VERBOSE("Space points successfully assigned FTF ID") ; - Acts::SeedFinderFTF finder(m_cfg.seedFinderConfig); - //this is now calling on a core algorithm - //need this function as create_coords is needed for seeds - std::function( - const SimSpacePoint *sp)> - create_coordinates = [](const SimSpacePoint *sp) { - Acts::Vector3 position(sp->x(), sp->y(), sp->z()); - Acts::Vector2 variance(sp->varianceR(), sp->varianceZ()); - return std::make_pair(position, variance); - }; - //output of function needed for seed + return FTF_spacePoints ; //not sure if I also need to return normal space point vector +} - - finder.loadSpacePoints(FTF_spacePoints); +std::vector ActsExamples::SeedingFTFAlgorithm::LayerNumbering() const { + + std::vector input_vector ; + std::vector count_vector ; - //still to develop, input will be FTF_spacePoints - SimSeedContainer seeds = finder.createSeeds(m_cfg.seedFinderOptions, - spacePoints, create_coordinates); + // //make a map of combined ID, vol, lay, z, r, mod id + // std::map> filling_map ; + // fstream fout; + // fout.open("Module_loop_sensitives.csv", ios::out | ios::app); - + for (Acts::GeometryIdentifier geoId : m_cfg.geometrySelection) { //think this is the volume loop - m_outputSeeds(ctx, std::move(seeds)); + m_cfg.trackingGeometry->visitSurfaces([this, &input_vector, &count_vector](const Acts::Surface* surface) { + Acts::GeometryIdentifier geoid = surface->geometryId() ; + auto ACTS_vol_id = geoid.volume() ; + auto ACTS_lay_id = geoid.layer() ; + auto mod_id = geoid.sensitive() ; + auto bounds_vect = surface->bounds().values() ; + auto center = surface->center(Acts::GeometryContext()) ; //vector of 3 values //this needs geo context + + // std::cout << "seeing what mod info is " << mod_id << std::endl ; + //make bounds global + Acts::Vector3 globalFakeMom(1, 1, 1); //fake mom, idea from hough + Acts::Vector2 min_bound_local = Acts::Vector2(bounds_vect[0],bounds_vect[1]) ; + Acts::Vector2 max_bound_local = Acts::Vector2(bounds_vect[2],bounds_vect[3]) ; + Acts::Vector3 min_bound_global = surface->localToGlobal(Acts::GeometryContext(),min_bound_local, globalFakeMom) ; + Acts::Vector3 max_bound_global = surface->localToGlobal(Acts::GeometryContext(),max_bound_local, globalFakeMom) ; + + if(min_bound_global(0)>max_bound_global(0)){ //checking that not wrong way round + min_bound_global.swap(max_bound_global) ; + } + + float rc=0.0; + float minBound = 100000.0; + float maxBound =-100000.0; + + + + //convert to FTF ID + auto ACTS_joint_id = ACTS_vol_id*100 + ACTS_lay_id ; + auto key = std::make_pair(ACTS_joint_id,0) ; //here the key needs to be pair of(vol*100+lay, 0) + auto Find = m_cfg.ACTS_FTF_Map.find(key) ; + // int FTF_id = Find->second ; + int FTF_id = Find->second.first ; //new map, item is pair want first + if (Find == m_cfg.ACTS_FTF_Map.end()){ //if end then make new key of (vol*100+lay, modid) + key = std::make_pair(ACTS_joint_id,mod_id) ; //mod ID + Find = m_cfg.ACTS_FTF_Map.find(key) ; + FTF_id = Find->second.first; + // std::cout << "keys not for mod 0 " << ACTS_joint_id << " mod id: " << mod_id << " FTF: " << FTF_id<< std::endl ; + + } + + short barrel_ec = 0; //a variable that says if barrrel, 0 = barrel, need to find what the n values are + // int eta_mod = 0 ; //could set eta mod to map memeber here, 80s have 0 in map too + int eta_mod = Find->second.second ; + + //assign barrel_ec depending on FTF_layer + if(79 < FTF_id && FTF_id < 85 ){ //80s, barrel + barrel_ec = 0 ; + // eta_mod = 0 ; + } + else if(89 < FTF_id && FTF_id < 99) {//90s positive + barrel_ec = 2 ; + // eta_mod = Find->second->second ; //access second member of item + } + else { //70s negative + barrel_ec = -2 ; + // eta_mod = Find->second->second ; + // std::cout << "checking some eta mod values are correct " << eta_mod << std::endl ; + + } + + + + if(barrel_ec == 0){ + rc = sqrt(center(0)*center(0)+center(1)*center(1)); //barrel center in r + //bounds of z + if(min_bound_global(2) < minBound) minBound = min_bound_global(2); + if(max_bound_global(2) > maxBound) maxBound = max_bound_global(2); + } + else{ + rc = center(2); //check this is right, not barrel center in Z + //bounds of r + float min = sqrt(min_bound_global(0)*min_bound_global(0)+min_bound_global(1)*min_bound_global(1)) ; + float max = sqrt(max_bound_global(0)*max_bound_global(0)+max_bound_global(1)*max_bound_global(1)) ; + if( min < minBound) minBound = min; + if( max > maxBound) maxBound = max ; + } + + + int combined_id = FTF_id*1000 + eta_mod ; + auto current_index = find_if(input_vector.begin(), input_vector.end(),[combined_id](auto n) { return n.m_subdet == combined_id; }); + if (current_index != input_vector.end()) { //not end so does exist + // //add to old, need index. FTF ID and type stay same! + size_t index = std::distance(input_vector.begin(), current_index); + input_vector[index].m_refCoord += rc ; + input_vector[index].m_minBound += minBound ; + input_vector[index].m_maxBound += maxBound ; + count_vector[index] += 1 ; //increase count at the index + + } + else { //end so doesnt exists + //make new if one with FTF ID doesnt exist: + Acts::TrigInDetSiLayer new_FTF_ID(combined_id, barrel_ec, rc, minBound, maxBound) ; + input_vector.push_back(new_FTF_ID) ; + count_vector.push_back(1) ; //so the element exists and not divinding by 0 + + } - return ActsExamples::ProcessCode::SUCCESS; -} + + // //temporary making map + // int ACTS_IDs = ACTS_vol_id*100 + ACTS_lay_id; + // if (filling_map.find(ACTS_IDs) != filling_map.end()) { //not end so does exist + // filling_map[ACTS_IDs][2] += center(2) ; //z + // filling_map[ACTS_IDs][3] += sqrt(center(0)*center(0)+center(1)*center(1)) ; //r + // filling_map[ACTS_IDs][4] += 1 ; //increase count + + // } + // else { //end so doesnt exists + // filling_map[ACTS_IDs] = {ACTS_vol_id, ACTS_lay_id,center(2),sqrt(center(0)*center(0)+center(1)*center(1)) ,1 } ; + // } + + //print to csv for each module + // fout << ACTS_vol_id << ", " //vol + // << ACTS_lay_id << ", " //lay + // << mod_id << ", " //module + // << center(2) << ", " //z + // << sqrt(center(0)*center(0)+center(1)*center(1)) //r + // << "\n"; + + + + + }); + + + } + + // fstream fout; + // fout.open("Module_loop.csv", ios::out | ios::app); + // for (auto i : filling_map){ + // fout << i.second[0] << ", " //vol + // << i.second[1] << ", " //lay + // << i.second[2]/i.second[4] << ", " //z + // << i.second[3]/i.second[4] //r + // << "\n"; + // } + + for (int i = 0; i < input_vector.size(); i++){ + input_vector[i].m_refCoord = input_vector[i].m_refCoord/count_vector[i] ; + //do I need to also divide bounds? + // std::cout << "checking vector is correct" << input_vector[i].m_subdet << std::endl ; + + } + // std::cout << "checking vector is filled" << input_vector.size() << count_vector.size(); + + return input_vector ; + + +} diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index 7590c7731f1..307458f8b61 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -315,9 +315,12 @@ def addSeeding( seedFinderConfigArg, seedFinderOptionsArg, seedFilterConfigArg, + trackingGeometry, logLevel, layerMappingConfigFile, + geoSelectionConfigFile, fastrack_inputConfigFile, + ) else: logger.fatal("unknown seedingAlgorithm %s", seedingAlgorithm) @@ -766,9 +769,12 @@ def addFTFSeeding( seedFinderConfigArg: SeedFinderConfigArg, seedFinderOptionsArg: SeedFinderOptionsArg, seedFilterConfigArg: SeedFilterConfigArg, + trackingGeometry: acts.TrackingGeometry, logLevel: acts.logging.Level = None, layerMappingConfigFile: Union[Path, str] = None, + geoSelectionConfigFile: Union[Path, str] = None, fastrack_inputConfigFile: Union[Path, str] = None, + ): """FTF seeding """ @@ -861,6 +867,11 @@ def addFTFSeeding( seedFinderConfig=seedFinderConfig, seedFinderOptions=seedFinderOptions, layerMappingFile=layerMappingFile, + geometrySelection = acts.examples.readJsonGeometryList( + str(geoSelectionConfigFile) + ), + inputSourceLinks = "sourcelinks" , + trackingGeometry = trackingGeometry, ) diff --git a/Examples/Python/src/TrackFinding.cpp b/Examples/Python/src/TrackFinding.cpp index d191d51c7d2..58576df655d 100644 --- a/Examples/Python/src/TrackFinding.cpp +++ b/Examples/Python/src/TrackFinding.cpp @@ -191,8 +191,8 @@ void addTrackFinding(Context& ctx) { ACTS_PYTHON_MEMBER(maxSeedsPerSpM); ACTS_PYTHON_MEMBER(collisionRegionMin); ACTS_PYTHON_MEMBER(collisionRegionMax); - // ACTS_PYTHON_MEMBER(phiMin); - // ACTS_PYTHON_MEMBER(phiMax); + ACTS_PYTHON_MEMBER(phiMin); + ACTS_PYTHON_MEMBER(phiMax); ACTS_PYTHON_MEMBER(zMin); ACTS_PYTHON_MEMBER(zMax); ACTS_PYTHON_MEMBER(rMax); @@ -214,6 +214,11 @@ void addTrackFinding(Context& ctx) { ACTS_PYTHON_MEMBER(centralSeedConfirmationRange); ACTS_PYTHON_MEMBER(forwardSeedConfirmationRange); ACTS_PYTHON_MEMBER(fastrack_input_file); + ACTS_PYTHON_MEMBER(m_phiSliceWidth); + ACTS_PYTHON_MEMBER(m_nMaxPhiSlice); + ACTS_PYTHON_MEMBER(m_useTrigSeedML); + ACTS_PYTHON_MEMBER(input_vector); + ACTS_PYTHON_STRUCT_END(); patchKwargsConstructor(c); @@ -292,7 +297,7 @@ void addTrackFinding(Context& ctx) { ACTS_PYTHON_DECLARE_ALGORITHM( ActsExamples::SeedingFTFAlgorithm, mex, "SeedingFTFAlgorithm", inputSpacePoints, outputSeeds, - seedFilterConfig, seedFinderConfig, seedFinderOptions, layerMappingFile); + seedFilterConfig, seedFinderConfig, seedFinderOptions, layerMappingFile, geometrySelection, inputSourceLinks, trackingGeometry, ACTS_FTF_Map); ACTS_PYTHON_DECLARE_ALGORITHM(