diff --git a/Tracker/TrackerRecAlgs/TrackerSeedFinder/CMakeLists.txt b/Tracker/TrackerRecAlgs/TrackerSeedFinder/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7aea7a085b439165e216db77e26aecc78eb5bdce --- /dev/null +++ b/Tracker/TrackerRecAlgs/TrackerSeedFinder/CMakeLists.txt @@ -0,0 +1,23 @@ +################################################################################ +# Package: TrackerSeedFinder +############################################# + +# Declare the package name: +atlas_subdir( TrackerSeedFinder ) + +# External dependencies: +find_package( Eigen ) + +# Component(s) in the package: +atlas_add_library( TrackerSeedFinderLib + src/components/*.cxx src/*.cxx src/*.h + INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} + LINK_LIBRARIES ${EIGEN_LIBRARIES} AthenaBaseComps AthContainers GeoPrimitives Identifier GaudiKernel TrackerReadoutGeometry TrackerRawData TrackerSimData GeneratorObjects TrackerSimEvent TrackerSpacePoint VxVertex FaserDetDescr xAODEventInfo TrackerIdentifier TrackerPrepRawData AthenaMonitoringKernelLib) + +atlas_add_component( TrackerSeedFinder + src/components/*.cxx src/*.cxx src/*.h + INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} + LINK_LIBRARIES ${EIGEN_LIBRARIES} AthenaBaseComps AthContainers GeoPrimitives Identifier GaudiKernel TrackerReadoutGeometry TrackerRawData TrackerSimData GeneratorObjects TrackerSimEvent TrackerSpacePoint VxVertex FaserDetDescr xAODEventInfo TrackerIdentifier TrackerPrepRawData AthenaMonitoringKernelLib) + +atlas_install_python_modules( python/*.py ) +atlas_install_scripts( test/*.py ) diff --git a/Tracker/TrackerRecAlgs/TrackerSeedFinder/python/TrackerSeedFinderConfig.py b/Tracker/TrackerRecAlgs/TrackerSeedFinder/python/TrackerSeedFinderConfig.py new file mode 100644 index 0000000000000000000000000000000000000000..acfbb4e7c80e315b357094519d03e2049e26b593 --- /dev/null +++ b/Tracker/TrackerRecAlgs/TrackerSeedFinder/python/TrackerSeedFinderConfig.py @@ -0,0 +1,37 @@ +"""Define methods to construct configured SCT Digitization tools and algorithms + +Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +""" +from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator +from AthenaConfiguration.ComponentFactory import CompFactory + +Tracker__TrackerSeedFinder, THistSvc=CompFactory.getComps("Tracker::TrackerSeedFinder", "THistSvc") + +from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg + + + +def TrackerSeedFinderBasicCfg(flags, **kwargs): + """Return ComponentAccumulator for TrackerSeedFinder""" + acc = ComponentAccumulator() + kwargs.setdefault("SpacePointsSCTName", "SCT_SpacePointContainer") + kwargs.setdefault("FaserSpacePointsSeedsName", "Seeds_SpacePointContainer") + acc.addEventAlgo(Tracker__TrackerSeedFinder(**kwargs)) + # attach ToolHandles + return acc + +def TrackerSeedFinder_OutputCfg(flags): + """Return ComponentAccumulator with Output for SCT. Not standalone.""" + acc = ComponentAccumulator() + acc.merge(OutputStreamCfg(flags, "ESD")) + ostream = acc.getEventAlgo("OutputStreamESD") + ostream.TakeItemsFromInput = True + return acc + +def TrackerSeedFinderCfg(flags, **kwargs): + acc=TrackerSeedFinderBasicCfg(flags, **kwargs) + histSvc= THistSvc() + histSvc.Output += [ "TrackerSeedFinder DATAFILE='trackseedfinder.root' OPT='RECREATE'" ] + acc.addService(histSvc) + acc.merge(TrackerSeedFinder_OutputCfg(flags)) + return acc diff --git a/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/TrackerSeedFinder.cxx b/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/TrackerSeedFinder.cxx new file mode 100755 index 0000000000000000000000000000000000000000..f8aef6daed4a6d9af723ccd7ef7c4fc573c28c6c --- /dev/null +++ b/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/TrackerSeedFinder.cxx @@ -0,0 +1,366 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + */ + +/*************************************************************************** + ------------------- + ATLAS Collaboration + ***************************************************************************/ + +//<<<<<< INCLUDES >>>>>> + + +#include "TrackerSeedFinder.h" + +// For processing clusters +#include "TrackerReadoutGeometry/SiLocalPosition.h" +#include "TrackerReadoutGeometry/SiDetectorDesign.h" +#include "TrackerReadoutGeometry/SiDetectorElement.h" + +// Space point Classes, +#include "TrkSpacePoint/SpacePointCollection.h" +#include "TrackerIdentifier/FaserSCT_ID.h" + +// general Atlas classes +#include "FaserDetDescr/FaserDetectorID.h" +#include "xAODEventInfo/EventInfo.h" +#include "StoreGate/ReadCondHandle.h" + +#include "AthenaMonitoringKernel/Monitored.h" + +//!!!!!!!!!!!!!!!!!!!!!!!! +//#include "Acts/EventData/TrackParameters.hpp" +#include "TrackerReadoutGeometry/SCT_DetectorManager.h" +#include "Acts/Utilities/detail/periodic.hpp" +#include "Acts/Definitions/Common.hpp" +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Definitions/Units.hpp" +using namespace Acts::UnitLiterals; +//!!!!!!!!!!!!!!!!!!!!!!!! +namespace Tracker +{ + + //------------------------------------------------------------------------ + TrackerSeedFinder::TrackerSeedFinder(const std::string& name, + ISvcLocator* pSvcLocator) + : AthReentrantAlgorithm(name, pSvcLocator) + , m_hist_n(0) + , m_hist_x(0) + , m_hist_y(0) + , m_hist_z(0) + , m_hist_r(0) + , m_hist_phi(0) + , m_hist_eta(0) + , m_hist_layer(0) + , m_hist_strip(0) + , m_hist_station(0) + , m_hist_x_z(0) + , m_hist_y_z(0) + , m_hist_sp_plane (0) + , m_hist_sp_layer (0) + , m_hist_sp_station (0) + , m_thistSvc("THistSvc", name) + {} + + //----------------------------------------------------------------------- + StatusCode TrackerSeedFinder::initialize() { + + ATH_MSG_DEBUG( "TrackerSeedFinder::initialize()" ); + + CHECK(m_thistSvc.retrieve()); + // Check that clusters, space points and ids have names + if ( m_Sct_spcontainerKey.key().empty()){ + ATH_MSG_FATAL( "SCTs selected and no name set for SCT clusters"); + return StatusCode::FAILURE; + } + ATH_CHECK( m_Sct_spcontainerKey.initialize() ); + + // create containers (requires the Identifier Helpers) + ATH_CHECK(detStore()->retrieve(m_idHelper,"FaserSCT_ID")); + + // Initialize the key of input SiElementPropertiesTable and SiDetectorElementCollection for SCT + ATH_CHECK(m_SCTDetEleCollKey.initialize()); + if (m_seed_spcontainerKey.key().empty()){ + ATH_MSG_FATAL( "No name set for output seeds space points"); + return StatusCode::FAILURE; + } + + ATH_CHECK( m_seed_spcontainerKey.initialize() ); + + ATH_CHECK( m_trackerSeedContainerKey.initialize() ); + if (m_trackerSeedContainerKey.key().empty()){ + ATH_MSG_FATAL( "No name set for output track seeds"); + return StatusCode::FAILURE; + } + + m_hist_n=new TH1D("sp_n","sp_n",20,0,20); + m_hist_x=new TH1D("sp_x","sp_x",100,-200,200); + m_hist_y=new TH1D("sp_y","sp_y",100,-200,200); + m_hist_z=new TH1D("sp_z","sp_z",3500,0,3500); + m_hist_r=new TH1D("sp_r","sp_r",100,0,200); + m_hist_eta=new TH1D("sp_eta","sp_eta",100,0,5); + m_hist_phi=new TH1D("sp_phi","sp_phi",100,-3.2,3.2); + m_hist_strip=new TH1D("sp_strip","sp_strip",1000,0,1000); + m_hist_layer=new TH1D("sp_layer","sp_layer",100,-10,10); + m_hist_station=new TH1D("sp_station","sp_station",100,-10,10); + m_hist_sp_station=new TH1D("sp_all_station","sp_station",100,-10,10); + m_hist_sp_plane=new TH1D("sp_all_plane","sp_station",100,-10,10); + m_hist_sp_layer=new TH1D("sp_all_layer","sp_station",100,-10,10); + m_hist_x_z=new TH2D("sp_x_z","sp_x_z",100,-200,200,3500,0,3500); + m_hist_y_z=new TH2D("sp_y_z","sp_y_z",100,-200,200,3500,0,3500); + m_hist_dx=new TH1D("sp_dx","sp_dx",100,-200,200); + m_hist_dy=new TH1D("sp_dy","sp_dy",100,-200,200); + m_hist_dx_slope=new TH1D("sp_dx_slope","sp_dx_slope",100,-200,200); + m_hist_dy_slope=new TH1D("sp_dy_slope","sp_dy_slope",100,-200,200); + m_hist_dx_intercept=new TH1D("sp_dx_intercept","sp_dx_intercept",100,-200,200); + m_hist_dx_intercept_after=new TH1D("sp_dx_intercept_after","sp_dx_intercept_after",100,-200,200); + m_hist_line=new TH1D("sp_line","sp_line",100,-200,200); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_n",m_hist_n)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_x",m_hist_x)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_y",m_hist_y)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_z",m_hist_z)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_r",m_hist_r)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_eta",m_hist_eta)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_phi",m_hist_phi)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_strip",m_hist_strip)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_layer",m_hist_layer)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_station",m_hist_station)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_all_station",m_hist_sp_station)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_all_layer",m_hist_sp_layer)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_all_plane",m_hist_sp_plane)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_x_z",m_hist_x_z)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_y_z",m_hist_y_z)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_dx",m_hist_dx)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_dy",m_hist_dy)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_dx_slope",m_hist_dx_slope)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_dy_slope",m_hist_dy_slope)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_dx_intercept",m_hist_dx_intercept)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_dx_intercept_after",m_hist_dx_intercept_after)); + CHECK(m_thistSvc->regHist("/TrackerSeedFinder/sp/sp_line",m_hist_line)); + + ATH_MSG_INFO( "TrackerSeedFinder::initialized for package version " << PACKAGE_VERSION ); + return StatusCode::SUCCESS; + } + + //------------------------------------------------------------------------- + + StatusCode TrackerSeedFinder::make_triplets(vector<vector<const Trk::SpacePoint*> >& vsp, vector<seed>& vt, string st) const { + + int count=0; + double xs=0, ys=0, zs=0, z2s=0, xzs=0, yzs=0; + + for (unsigned int i=0; i<vsp[0].size(); i++) { + for (unsigned int j=0; j<vsp[1].size(); j++) { + for (unsigned int k=0; k<vsp[2].size(); k++) { + + ATH_MSG_VERBOSE( " station " << st << " / list of space points for seeds " + << vsp[0].at(i)->clusterList().first->identify() << " " + << vsp[1].at(j)->clusterList().first->identify() << " " + << vsp[2].at(k)->clusterList().first->identify()); + + count++; + + vector<double> x; vector<double> y; vector<double> z; + x.push_back(vsp[0].at(i)->globalPosition().x()); x.push_back(vsp[1].at(j)->globalPosition().x()); x.push_back(vsp[2].at(k)->globalPosition().x()); + y.push_back(vsp[0].at(i)->globalPosition().y()); y.push_back(vsp[1].at(j)->globalPosition().y()); y.push_back(vsp[2].at(k)->globalPosition().y()); + z.push_back(vsp[0].at(i)->globalPosition().z()); z.push_back(vsp[1].at(j)->globalPosition().z()); z.push_back(vsp[2].at(k)->globalPosition().z()); + + xs=x.at(0)+x.at(1)+x.at(2); ys=y.at(0)+y.at(1)+y.at(2); zs=z.at(0)+z.at(1)+z.at(2); + z2s=pow(z.at(0),2)+pow(z.at(1),2)+pow(z.at(2),2); + xzs=x.at(0)*z.at(0)+x.at(1)*z.at(1)+x.at(2)*z.at(2); + yzs=y.at(0)*z.at(0)+y.at(1)*z.at(1)+y.at(2)*z.at(2); + + seed mt; + mt.axz=(3*xzs-xs*zs)/(3*z2s-zs*zs); + mt.bxz=(z2s*xs-xzs*zs)/(3*z2s-zs*zs); + mt.ayz=(3*yzs-ys*zs)/(3*z2s-zs*zs); + mt.byz=(z2s*ys-yzs*zs)/(3*z2s-zs*zs); + mt.add_sp(vsp[0].at(i)); mt.add_sp(vsp[1].at(j)); mt.add_sp(vsp[2].at(k)); + mt.station=st; + mt.num=count; + + for(int pos=0; pos<3; pos++) { + mt.chi2_xz+=pow(x.at(pos)-(mt.axz*z.at(pos)+mt.bxz),2); + mt.chi2_yz+=pow(x.at(pos)-(mt.ayz*z.at(pos)+mt.byz),2); + } + + ATH_MSG_VERBOSE( " x1 " << x.at(0) << "; x2 " << x.at(1) << "; x3 " << x.at(2)); + ATH_MSG_VERBOSE( " y1 " << y.at(0) << "; y2 " << y.at(1) << "; y3 " << y.at(2)); + ATH_MSG_VERBOSE( " z1 " << z.at(0) << "; z2 " << z.at(1) << "; z3 " << z.at(2)); + ATH_MSG_VERBOSE( " linear fit on plane xz / slope " << mt.axz << "; intercept " << mt.bxz); + ATH_MSG_VERBOSE( " linear fit on plane yz / slope " << mt.ayz << "; intercept " << mt.byz); + ATH_MSG_VERBOSE( " chi2 / on plane xz " << mt.chi2_xz << "; on plane yz " << mt.chi2_yz); + + vt.push_back(mt); + + } + } + } + + return StatusCode::SUCCESS; + } + + //------------------------------------------------------------------------- + + StatusCode TrackerSeedFinder::execute (const EventContext& ctx) const { + + ++m_numberOfEvents; + N_1_0=0, N_1_1=0, N_1_2=0, N_2_0=0, N_2_1=0, N_2_2=0, N_3_0=0, N_3_1=0, N_3_2=0; + + // retrieve tracker spacepoint container + SG::ReadHandle<SpacePointContainer> sct_spcontainer( m_Sct_spcontainerKey, ctx ); + if (!sct_spcontainer.isValid()){ + msg(MSG:: FATAL) << "Could not find the data object "<< sct_spcontainer.name() << " !" << endmsg; + return StatusCode::RECOVERABLE; + } + + ATH_MSG_DEBUG( "Tracker spacepoint container found: " << sct_spcontainer->size() << " collections" ); + SpacePointContainer::const_iterator it = sct_spcontainer->begin(); + SpacePointContainer::const_iterator itend = sct_spcontainer->end(); + + int i=0; + + vector<vector<const Trk::SpacePoint*> > vsp1(3); + vector<vector<const Trk::SpacePoint*> > vsp2(3); + vector<vector<const Trk::SpacePoint*> > vsp3(3); + + vector<pair<int, const Trk::SpacePoint*>> msp; + + vector<vector<pair<int, const Trk::SpacePoint*>>> mseeds; + vector<int> pos; + + ATH_MSG_DEBUG( "Start iteration of spacepoint collections" ); + for (; it != itend; ++it){ + + ++m_numberOfSPCollection; + const SpacePointCollection *colNext=&(**it); + int nReceivedSPSCT = colNext->size(); + + // Create SpacePointCollection + IdentifierHash idHash = colNext->identifyHash(); + Identifier elementID = colNext->identify(); + + ATH_MSG_DEBUG( "Spacepoint collection in iteraction: size = " <<nReceivedSPSCT <<", IDHash = "<<idHash<<", ID = "<<elementID ); + if (nReceivedSPSCT== 0){ + ATH_MSG_VERBOSE( "Algorithm found no space points" ); + ++m_numberOfEmptySPCollection; + } else { + SpacePointCollection::const_iterator sp_begin= colNext->begin(); + SpacePointCollection::const_iterator sp_end= colNext->end(); + + ATH_MSG_DEBUG( "Iterate the spacepoint in collection " ); + + for (; sp_begin != sp_end; ++sp_begin) { + + ++i; + ++m_numberOfSP; + const Trk::SpacePoint* sp=&(**sp_begin); + + const auto identifier = sp->clusterList().first->identify(); + int station = m_idHelper->station(identifier); + int plane = m_idHelper->layer(identifier); + + ATH_MSG_VERBOSE( " layer " << (station-1)*3+plane ); + msp.push_back(make_pair((station-1)*3+plane,sp)); + if ((station-1)*3+plane < 3) { + vsp1.at(plane).push_back(sp); + } else if ((station-1)*3+plane < 6) { + vsp2.at(plane).push_back(sp); + } else if ((station-1)*3+plane < 9) { + vsp3.at(plane).push_back(sp); + } + + if (station==1 && plane==0) {N_1_0++;} if (station==1 && plane==1) {N_1_1++;} if (station==1 && plane==2) {N_1_2++;} + if (station==2 && plane==0) {N_2_0++;} if (station==2 && plane==1) {N_2_1++;} if (station==2 && plane==2) {N_2_2++;} + if (station==3 && plane==0) {N_3_0++;} if (station==3 && plane==1) {N_3_1++;} if (station==3 && plane==2) {N_3_2++;} + + pos.push_back((station-1)*3+plane); + + ATH_MSG_VERBOSE( " spacepoint n " << m_numberOfSP ); + ATH_MSG_VERBOSE( " station " << station << " plane " << plane << " pos " << pos.at(i-1) << " index " << (station-1)*3+plane); + ATH_MSG_VERBOSE( " i " << i << " x " << sp->globalPosition().x() << " y " << sp->globalPosition().y() << " z " << sp->globalPosition().z()); + + m_hist_r->Fill(sp->r()); + m_hist_eta->Fill(sp->eta()); + m_hist_phi->Fill(sp->phi()); + + m_hist_x->Fill(sp->globalPosition().x()); + m_hist_y->Fill(sp->globalPosition().y()); + m_hist_z->Fill(sp->globalPosition().z()); + + m_hist_x_z->Fill(sp->globalPosition().x(),sp->globalPosition().z()); + m_hist_y_z->Fill(sp->globalPosition().y(),sp->globalPosition().z()); + + } + } + } + + ATH_MSG_VERBOSE( " number of space points; event " << m_numberOfEvents); + ATH_MSG_VERBOSE( " 1st station " << N_1_0+N_1_1+N_1_2 << " (" << vsp1.at(0).size() << ";" << vsp1.at(1).size() << ";" << vsp1.at(2).size() << ")"); + ATH_MSG_VERBOSE( " 2nd station " << N_2_0+N_2_1+N_2_2 << " (" << vsp2.at(0).size() << ";" << vsp2.at(1).size() << ";" << vsp2.at(2).size() << ")"); + ATH_MSG_VERBOSE( " 3rd station " << N_3_0+N_3_1+N_3_2 << " (" << vsp3.at(0).size() << ";" << vsp3.at(1).size() << ";" << vsp3.at(2).size() << ")"); + + vector<seed> vseed; + ATH_CHECK(make_triplets(vsp1, vseed, "1")); + ATH_CHECK(make_triplets(vsp2, vseed, "2")); + + vector<seed> vfseed; + for (vector<seed>::iterator it1 = vseed.begin(); it1 != vseed.end(); ++it1) { + for (vector<seed>::iterator it2 = vseed.begin(); it2 != vseed.end(); ++it2) { + + if ((*it1).station == "1" && (*it2).station == "2") { + + ATH_MSG_VERBOSE( "Considering seeds " << (*it1).num << " and " << (*it2).num); + + seed ms; + ms.station="12"; + ms.add_vsp((*it1).vsp); + ms.add_vsp((*it2).vsp); + vfseed.push_back(ms); + } + } + } + + SG::WriteHandle<TrackerSeedCollection> seedContainer(m_trackerSeedContainerKey, ctx); + ATH_CHECK(seedContainer.record( std::make_unique<TrackerSeedCollection>() ) ); + ATH_MSG_INFO("Created track seed container " << m_trackerSeedContainerKey.key()); + + int nseed=0; + + for (vector<seed>::iterator it = vfseed.begin(); it != vfseed.end(); ++it) { + + if ((*it).station != "12") continue; + + nseed++; + + vector<const Trk::SpacePoint*> mseed = (*it).vsp; + + Tracker::TrackerSeed* trackerSeed = new Tracker::TrackerSeed(); + trackerSeed->set_id(TrackerSeed::TRIPLET_SP_FIRSTSTATION); + trackerSeed->add(mseed); + + seedContainer->push_back(trackerSeed); + } + + ATH_MSG_INFO("Saved " << nseed << " seeds in container"); + + return StatusCode::SUCCESS; + } + + //--------------------------------------------------------------------------- + StatusCode TrackerSeedFinder::finalize() + { + ATH_MSG_INFO( "Finalizing" ); + ATH_MSG_INFO( m_numberOfEvents << " events processed" ); + ATH_MSG_INFO( m_numberOfSPCollection << " spacepoint collections processed" ); + ATH_MSG_INFO( m_numberOfEmptySPCollection<< " spacepoint collections empty" ); + ATH_MSG_INFO( m_numberOfSP<< " sct SP collections processed" ); + + ATH_MSG_INFO( "Finalizing TrackerSeedFinder" ); + + return StatusCode::SUCCESS; + } + + //-------------------------------------------------------------------------- + +} diff --git a/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/TrackerSeedFinder.h b/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/TrackerSeedFinder.h new file mode 100755 index 0000000000000000000000000000000000000000..eabebe327c8d693b2f30e803ed778bd8b4916176 --- /dev/null +++ b/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/TrackerSeedFinder.h @@ -0,0 +1,135 @@ +/* + Copyright (C) 2021 CERN for the benefit of the FASER collaboration + */ + +/** @file TrackSeedFinder.h + * an algorithm for finding track seeds + * @author Andrea Coccaro + * @date May 2021 + */ + + +#ifndef TRACKERSEEDFINDER_TRACKERSEEDFINDER_H +#define TRACKERSEEDFINDER_TRACKERSEEDFINDER_H + +#include "StoreGate/ReadCondHandleKey.h" +#include "AthenaBaseComps/AthReentrantAlgorithm.h" +#include "Identifier/Identifier.h" + +#include "GeneratorObjects/McEventCollection.h" +#include "TrackerPrepRawData/FaserSCT_ClusterCollection.h" +#include "TrackerPrepRawData/FaserSCT_ClusterContainer.h" +#include "TrackerPrepRawData/TrackerClusterContainer.h" +#include "TrackerReadoutGeometry/SiDetectorElementCollection.h" +#include "TrkSpacePoint/SpacePoint.h" +#include "TrkSpacePoint/SpacePointContainer.h" +#include "TrackerSpacePoint/SpacePointForSeedCollection.h" + +#include "TrackerPrepRawData/TrackerSeedCollection.h" +#include "TrackerPrepRawData/TrackerSeed.h" +#include "TrkSpacePoint/SpacePointOverlapCollection.h" +#include "TrackerSimEvent/FaserSiHitCollection.h" +#include "TrackerRawData/FaserSCT_RDO_Container.h" +#include "TrackerSimData/TrackerSimDataCollection.h" + + +#include "GaudiKernel/ServiceHandle.h" +#include "GaudiKernel/ITHistSvc.h" +#include "GaudiKernel/ToolHandle.h" + +#include <string> +#include <vector> +#include "TH1.h" +#include "TH2.h" + +#include <string> + +using namespace std; + +class FaserSCT_ID; + +namespace Tracker { + + class TrackerSeedFinder:public AthReentrantAlgorithm { + + public: + + TrackerSeedFinder(const std::string& name, ISvcLocator* pSvcLocator); + + virtual ~TrackerSeedFinder() = default; + + virtual StatusCode initialize() override; + + virtual StatusCode execute (const EventContext& ctx) const override; + + virtual StatusCode finalize() override; + + private: + + struct seed { + vector<const Trk::SpacePoint*> vsp; + double axz, bxz, ayz, byz; + double chi2_xz, chi2_yz; + string station; + int num; + + void add_sp(const Trk::SpacePoint* sp) { + vsp.push_back(sp); + } + + void add_vsp(vector<const Trk::SpacePoint*> v) { + for (vector<const Trk::SpacePoint*>::iterator it = v.begin(); it != v.end(); ++it) { + vsp.push_back((*it)); + } + } + }; + + StatusCode make_triplets(vector< vector<const Trk::SpacePoint*> >&, vector<seed>&, string) const; + + TrackerSeedFinder() = delete; + TrackerSeedFinder(const TrackerSeedFinder&) =delete; + TrackerSeedFinder &operator=(const TrackerSeedFinder&) = delete; + SG::ReadHandleKey<SpacePointContainer> m_Sct_spcontainerKey{this, "SpacePointsSCTName", "SCT spContainer"}; + + SG::WriteHandleKey<SpacePointForSeedCollection> m_seed_spcontainerKey{this, "FaserSpacePointsSeedsName", "SpacePointForSeedCollection", "SpacePointForSeedCollection"}; + SG::WriteHandleKey<Tracker::TrackerSeedCollection> m_trackerSeedContainerKey{this, "FaserTrackerSeedName", "FaserTrackerSeedCollection", "FaserTrackerSeedCollection"}; + + SG::ReadCondHandleKey<TrackerDD::SiDetectorElementCollection> m_SCTDetEleCollKey{this, "SCTDetEleCollKey", "SCT_DetectorElementCollection", "Key of SiDetectorElementCollection for SCT"}; + + const FaserSCT_ID* m_idHelper{nullptr}; + mutable std::atomic<int> m_numberOfEvents{0}; + mutable std::atomic<int> m_numberOfSPCollection{0}; + mutable std::atomic<int> m_numberOfEmptySPCollection{0}; + mutable std::atomic<int> m_numberOfSP{0}; + + TH1* m_hist_n; + TH1* m_hist_x; + TH1* m_hist_y; + TH1* m_hist_z; + TH1* m_hist_r; + TH1* m_hist_phi; + TH1* m_hist_eta; + TH1* m_hist_layer; + TH1* m_hist_strip; + TH1* m_hist_station; + TH2* m_hist_x_z; + TH2* m_hist_y_z; + TH1* m_hist_sp_plane; + TH1* m_hist_sp_layer; + TH1* m_hist_sp_station; + TH1* m_hist_dx; + TH1* m_hist_dy; + TH1* m_hist_dx_slope; + TH1* m_hist_dy_slope; + TH1* m_hist_dx_intercept; + TH1* m_hist_dx_intercept_after; + TH1* m_hist_line; + + ServiceHandle<ITHistSvc> m_thistSvc; + + mutable int N_1_0=0, N_1_1=0, N_1_2=0, N_2_0=0, N_2_1=0, N_2_2=0, N_3_0=0, N_3_1=0, N_3_2=0; + + }; + +} +#endif // TRACKERSEEDFINDER_TRACKERSEEDFINDER_H diff --git a/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/components/TrackerSeedFinder_entries.cxx b/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/components/TrackerSeedFinder_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..89e6db22cc8de4124d9ed41045ace3a79f430cb8 --- /dev/null +++ b/Tracker/TrackerRecAlgs/TrackerSeedFinder/src/components/TrackerSeedFinder_entries.cxx @@ -0,0 +1,3 @@ +#include "../TrackerSeedFinder.h" + +DECLARE_COMPONENT( Tracker::TrackerSeedFinder ) diff --git a/Tracker/TrackerRecAlgs/TrackerSeedFinder/test/TrackerSeedFinderDbg.py b/Tracker/TrackerRecAlgs/TrackerSeedFinder/test/TrackerSeedFinderDbg.py new file mode 100644 index 0000000000000000000000000000000000000000..c6334704f6aef383a1057cd6266efa8398d16a04 --- /dev/null +++ b/Tracker/TrackerRecAlgs/TrackerSeedFinder/test/TrackerSeedFinderDbg.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +"""Test various ComponentAccumulator Digitization configuration modules + +Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +""" +import sys +from AthenaCommon.Logging import log, logging +from AthenaCommon.Constants import DEBUG, VERBOSE, INFO +from AthenaCommon.Configurable import Configurable +from CalypsoConfiguration.AllConfigFlags import ConfigFlags +from AthenaConfiguration.TestDefaults import defaultTestFiles +from AthenaConfiguration.MainServicesConfig import MainServicesCfg +from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg +from AthenaPoolCnvSvc.PoolWriteConfig import PoolWriteCfg +from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg +#from Digitization.DigitizationParametersConfig import writeDigitizationMetadata +from TrackerPrepRawDataFormation.TrackerPrepRawDataFormationConfig import FaserSCT_ClusterizationCfg +from TrackerSpacePointFormation.TrackerSpacePointFormationConfig import TrackerSpacePointFinderCfg +from TrackerSeedFinder.TrackerSeedFinderConfig import TrackerSeedFinderCfg +#from MCTruthSimAlgs.RecoTimingConfig import MergeRecoTimingObjCfg + +# Set up logging and new style config +log.setLevel(DEBUG) +Configurable.configurableRun3Behavior = True + +# Configure +ConfigFlags.Input.Files = ['my.RDO.pool.root'] +ConfigFlags.Output.ESDFileName = "mySeeds.ESD.pool.root" +ConfigFlags.IOVDb.GlobalTag = "OFLCOND-XXXX-XXX-XX" +ConfigFlags.GeoModel.Align.Dynamic = False +#ConfigFlags.Concurrency.NumThreads = 1 +ConfigFlags.Beam.NumberOfCollisions = 0. + +ConfigFlags.lock() + +# Core components +acc = MainServicesCfg(ConfigFlags) +acc.merge(PoolReadCfg(ConfigFlags)) +acc.merge(PoolWriteCfg(ConfigFlags)) + +#acc.merge(writeDigitizationMetadata(ConfigFlags)) + +# Inner Detector +acc.merge(FaserSCT_ClusterizationCfg(ConfigFlags)) +acc.merge(TrackerSpacePointFinderCfg(ConfigFlags)) +acc.merge(TrackerSeedFinderCfg(ConfigFlags)) + +# Timing +#acc.merge(MergeRecoTimingObjCfg(ConfigFlags)) + +# Dump config +logging.getLogger('forcomps').setLevel(VERBOSE) +acc.foreach_component("*").OutputLevel = VERBOSE +acc.foreach_component("*ClassID*").OutputLevel = INFO +# acc.getCondAlgo("FaserSCT_AlignCondAlg").OutputLevel = VERBOSE +# acc.getCondAlgo("FaserSCT_DetectorElementCondAlg").OutputLevel = VERBOSE +acc.getService("StoreGateSvc").Dump = True +acc.getService("ConditionStore").Dump = True +acc.printConfig(withDetails=True) +ConfigFlags.dump() + +# Execute and finish +sc = acc.run(maxEvents=-1) + +# Success should be 0 +sys.exit(not sc.isSuccess()) diff --git a/Tracker/TrackerRecEvent/TrackerPrepRawData/CMakeLists.txt b/Tracker/TrackerRecEvent/TrackerPrepRawData/CMakeLists.txt index 1d7a2f71601ee4a1d46065687afd5db342890c93..d1630abf233ec25789022973377d7c17956c7dd0 100644 --- a/Tracker/TrackerRecEvent/TrackerPrepRawData/CMakeLists.txt +++ b/Tracker/TrackerRecEvent/TrackerPrepRawData/CMakeLists.txt @@ -15,7 +15,7 @@ atlas_add_library( TrackerPrepRawData PUBLIC_HEADERS TrackerPrepRawData INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} - LINK_LIBRARIES ${EIGEN_LIBRARIES} AthLinks CxxUtils AthenaKernel GeoPrimitives Identifier EventPrimitives GaudiKernel TrackerReadoutGeometry TrkSurfaces TrkEventPrimitives TrkPrepRawData TrackerRawData EventContainers + LINK_LIBRARIES ${EIGEN_LIBRARIES} AthLinks CxxUtils AthenaKernel GeoPrimitives Identifier EventPrimitives GaudiKernel TrackerReadoutGeometry TrkSurfaces TrkEventPrimitives TrkPrepRawData TrackerRawData EventContainers TrkSpacePoint PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} ) atlas_add_dictionary( TrackerPrepRawDataDict diff --git a/Tracker/TrackerRecEvent/TrackerPrepRawData/TrackerPrepRawData/TrackerSeed.h b/Tracker/TrackerRecEvent/TrackerPrepRawData/TrackerPrepRawData/TrackerSeed.h new file mode 100755 index 0000000000000000000000000000000000000000..02d6a193aa081bbd2188288131a98a6bb2708096 --- /dev/null +++ b/Tracker/TrackerRecEvent/TrackerPrepRawData/TrackerPrepRawData/TrackerSeed.h @@ -0,0 +1,50 @@ +#ifndef TRACKERRAWDATA_TRACKERSEED_H +#define TRACKERRAWDATA_TRACKERSEED_H + +#include "TrkSpacePoint/SpacePoint.h" + +#include <vector> + +using namespace std; + +class MsgStream; + +namespace Tracker { + + class TrackerSeed { + + public: + + enum StrategyId{NULLID=0, TRIPLET_SP_FIRSTSTATION=1}; + + TrackerSeed(); + TrackerSeed(const StrategyId, const TrackerSeed &); + virtual ~TrackerSeed(); + + TrackerSeed(const StrategyId, vector<const Trk::SpacePoint*> seed); + + void set_id(const StrategyId id) { m_strategyId = id; } + StrategyId id() const { return m_strategyId; } + + void add(vector<const Trk::SpacePoint*> seed); + + int size() const; + + TrackerSeed &operator=(const TrackerSeed &); + + virtual MsgStream& dump(MsgStream& stream) const; + virtual ostream& dump(ostream& stream) const; + + private: + + StrategyId m_strategyId; + vector<const Trk::SpacePoint*> m_seed; + + }; + + MsgStream& operator << (MsgStream& stream, const TrackerSeed& prd); + ostream& operator << (ostream& stream, const TrackerSeed& prd); + +} +#endif // TRACKERRAWDATA_TRACKERSEED_H + diff --git a/Tracker/TrackerRecEvent/TrackerPrepRawData/TrackerPrepRawData/TrackerSeedCollection.h b/Tracker/TrackerRecEvent/TrackerPrepRawData/TrackerPrepRawData/TrackerSeedCollection.h new file mode 100755 index 0000000000000000000000000000000000000000..a90dedca94ed8580d9fe74dac784fc9c0ee70e69 --- /dev/null +++ b/Tracker/TrackerRecEvent/TrackerPrepRawData/TrackerPrepRawData/TrackerSeedCollection.h @@ -0,0 +1,16 @@ +#ifndef TRACKERSEEDCOLLECTION_H +#define TRACKERSEEDCOLLECTION_H + +#include "AthenaKernel/CLASS_DEF.h" +#include "AthContainers/DataVector.h" +#include "GaudiKernel/DataObject.h" +#include "TrackerPrepRawData/TrackerSeed.h" + +namespace Tracker { + typedef DataVector<TrackerSeed> TrackerSeedCollection; +} + +CLASS_DEF(Tracker::TrackerSeedCollection, 1139531114, 1) + +#endif // TRACKERSEEDCOLLECTION_H + diff --git a/Tracker/TrackerRecEvent/TrackerPrepRawData/src/TrackerSeed.cxx b/Tracker/TrackerRecEvent/TrackerPrepRawData/src/TrackerSeed.cxx new file mode 100755 index 0000000000000000000000000000000000000000..bd217ec892f499994db0f6eb5d557669357a6ef7 --- /dev/null +++ b/Tracker/TrackerRecEvent/TrackerPrepRawData/src/TrackerSeed.cxx @@ -0,0 +1,44 @@ +#include "TrackerPrepRawData/TrackerSeed.h" + +namespace Tracker { + + TrackerSeed::TrackerSeed() : m_strategyId(NULLID) {} + + TrackerSeed::TrackerSeed(const StrategyId id, const TrackerSeed& trackerSeed) : m_strategyId(id), m_seed(trackerSeed.m_seed) {} + + TrackerSeed::~TrackerSeed() {} + + TrackerSeed::TrackerSeed(const StrategyId id, vector<const Trk::SpacePoint*> seed) { m_strategyId = id; m_seed = seed; } + + void TrackerSeed::add(vector<const Trk::SpacePoint*> seed) { m_seed = seed; } + + int TrackerSeed::size() const { return m_seed.size(); } + + TrackerSeed& TrackerSeed::operator=(const TrackerSeed& trackSeed){ + if(&trackSeed != this) { + TrackerSeed::operator=(trackSeed); + m_seed = trackSeed.m_seed; + } + return *this; + } + + MsgStream& TrackerSeed::dump(MsgStream& stream) const { + stream << "TrackerSeed object" << endl; + this->TrackerSeed::dump(stream); + return stream; + } + + ostream& TrackerSeed::dump(ostream& stream) const { + stream << "TrackerSeed object" << endl; + this->TrackerSeed::dump(stream); + return stream; + } + + MsgStream& operator << (MsgStream& stream, const TrackerSeed& trackSeed) { + return trackSeed.dump(stream); + } + + ostream& operator << (ostream& stream, const TrackerSeed& trackSeed) { + return trackSeed.dump(stream); + } +}