26#include "GaudiKernel/IEventProcessor.h"
29#ifdef BENCHMARK_FPGATRACKSIM
50 while (std::getline(
ss, line,
'\n')) {
56 const std::vector<Gaudi::Details::PropertyBase*> props = this->getProperties();
57 for( Gaudi::Details::PropertyBase* prop : props ) {
58 if (prop->ownerTypeName()==this->type()) {
59 ATH_MSG_DEBUG(
"Property:\t" << prop->name() <<
"\t : \t" << prop->toString());
98 return StatusCode::SUCCESS;
117 std::vector<std::unique_ptr<FPGATrackSimHit>> hits_miss;
124 SmartIF<IEventProcessor> appMgr{service(
"ApplicationMgr")};
126 ATH_MSG_ERROR(
"Failed to retrieve ApplicationMgr as IEventProcessor");
127 return StatusCode::FAILURE;
129 return appMgr->stopRun();
133 ATH_CHECK( FPGAHits.
record (std::make_unique<FPGATrackSimHitCollection>()));
136 ATH_CHECK( FPGAHitUnmapped.
record (std::make_unique<FPGATrackSimHitCollection>()));
139 ATH_CHECK( FPGAClusters.
record (std::make_unique<FPGATrackSimClusterCollection>()));
142 ATH_CHECK(truthLinkVec.
record(std::make_unique<xAODTruthParticleLinkVector>()));
145 ATH_CHECK(FPGATruthTracks.
record(std::make_unique<FPGATrackSimTruthTrackCollection>()));
148 ATH_CHECK(FPGAOfflineTracks.
record(std::make_unique<FPGATrackSimOfflineTrackCollection>()));
151 bool acceptEvent =
false;
155 if (eventSelector->selectEvent(eventHeader)) {
156 ATH_MSG_DEBUG(
"Event accepted by: " << eventSelector->name());
167 if (!truthParticleContainer.
isValid()) {
168 ATH_MSG_ERROR(
"No valid truth particle container with key " << truthParticleContainer.
key());
169 return StatusCode::FAILURE;
172 std::unordered_map<HepMcParticleLink::barcode_type, std::pair<const xAOD::TruthParticle*, size_t>> truthParticlesMap;
173 size_t truthParticleIndex = 0;
175 truthParticlesMap.insert(std::make_pair(
HepMC::uniqueID(truthParticle), std::make_pair(truthParticle,truthParticleIndex)));
176 truthParticleIndex++;
179 truthLinkVec->reserve(fpgaTruthTracks.size());
180 ATH_MSG_DEBUG(
"begin truth matching for " << fpgaTruthTracks.size() <<
" FPGA truth tracks");
182 auto it = truthParticlesMap.find(fpgaTruthTrack.getUniqueID());
183 if (it != truthParticlesMap.end()) {
191 if (truthLinkVec->empty()) {
192 ATH_MSG_DEBUG(
"No truth particles selected. Skipping event...");
193 return StatusCode::SUCCESS;
202 eventSelector->setSelectedEvent(
true);
211 hits_miss, clusters, FPGAHitUnmapped, FPGAClusters));
215 FPGATruthTracks->push_back(truthtrack);
220 FPGAOfflineTracks->push_back(offlineTrack);
231 const unsigned& regionID = eventSelector->getRegionID();
237 std::vector<FPGATrackSimHit>
const& hits = logicEventHeader.
towers().at(0).hits();
241 FPGAHits->reserve(hits.size());
242 for (
const auto& hit : hits) {
271 return StatusCode::SUCCESS;
280 const EventContext& ctx,
289 return StatusCode::SUCCESS;
298 ATH_MSG_DEBUG(
"Cannot read more events from file, returning");
299 return StatusCode::SUCCESS;
303 eventHeader = firstInputHeader;
311 ATH_MSG_INFO(
"Cannot read more events from file, returning");
312 return StatusCode::SUCCESS;
318 return StatusCode::SUCCESS;
327 std::vector<std::unique_ptr<FPGATrackSimHit>>& hits_miss,
334 logicEventHeader.
reset();
335 logicEventHeader_precluster.
reset();
339 ATH_CHECK(hitMapTool->convert(1, eventHeader, logicEventHeader));
344 for (
auto& hit : hits_miss) FPGAHitUnmapped->push_back(std::move(hit));
348 ATH_MSG_DEBUG(
"Hits conversion done, #unmapped hists = " << FPGAHitUnmapped->size());
352 logicEventHeader_precluster = logicEventHeader;
362 unsigned npix(0), nstrip(0);
364 if (cluster.getClusterEquiv().isPixel()) npix++;
381 while (npix > current_max_pix &&
386 while (nstrip > current_max_strip &&
391 unsigned clusters_size = clusters.size();
392 while (clusters_size > current_max_clusters &&
393 !
m_nMaxClusters.compare_exchange_weak(current_max_clusters, clusters_size));
396 FPGAClusters->insert(
398 std::make_move_iterator(clusters.begin()),
399 std::make_move_iterator(clusters.end()));
403 return StatusCode::SUCCESS;
411 ATH_MSG_INFO(
"PRINTING FPGATRACKSIM SIMPLE DATAPREP STATS");
412 ATH_MSG_INFO(
"========================================================================================");
419 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
std::vector< FPGATrackSimCluster > FPGATrackSimClusterCollection
: FPGATrackSim-specific class to represent an hit in the detector.
Maps ITK module indices to FPGATrackSim regions.
Stores slice definitions for FPGATrackSim regions.
Defines a class for roads.
Structs that store the 5 track parameters.
std::vector< FPGATrackSimTruthTrack > FPGATrackSimTruthTrackCollection
An algorithm that can be simultaneously executed in multiple threads.
ElementLink implementation for ROOT usage.
ToolHandleArray< FPGATrackSimRawToLogicalHitsTool > m_hitMapTools
SG::WriteHandleKey< FPGATrackSimOfflineTrackCollection > m_FPGAOfflineTrackKey
virtual StatusCode execute(const EventContext &ctx) const override final
SG::WriteHandleKey< FPGATrackSimHitCollection > m_FPGAHitUnmappedKey
Gaudi::Property< std::string > m_preClusterBranch
Gaudi::Property< bool > m_isDataPrepPipeline
Gaudi::Property< std::string > m_postClusterBranch
virtual StatusCode finalize() override
std::mutex m_rootWriteMutex
Gaudi::Property< bool > m_doEvtSel
SG::WriteHandleKey< FPGATrackSimTruthTrackCollection > m_FPGATruthTrackKey
FPGATrackSimLogicalEventInputHeader * m_logicEventHeader_precluster
ToolHandle< IFPGATrackSimInputTool > m_hitSGInputTool
Gaudi::Property< int > m_firstInputToolN
ToolHandle< FPGATrackSimOutputHeaderTool > m_writeOutputTool
StatusCode processInputs(const FPGATrackSimEventInputHeader &eventHeader, FPGATrackSimLogicalEventInputHeader &logicEventHeader, FPGATrackSimLogicalEventInputHeader &logicEventHeader_precluster, std::vector< std::unique_ptr< FPGATrackSimHit > > &hits_miss, FPGATrackSimClusterCollection &clusters, SG::WriteHandle< FPGATrackSimHitCollection > &FPGAHitUnmapped, SG::WriteHandle< FPGATrackSimClusterCollection > &FPGAClusters) const
virtual StatusCode initialize() override
Gaudi::Property< int > m_secondInputToolN
std::atomic< unsigned > m_nMaxStripClusters
ToolHandleArray< FPGATrackSim::FPGATrackSimEventSelectionTool > m_eventSelectionTools
std::atomic< unsigned > m_nMaxClusters
ToolHandle< FPGATrackSimReadRawRandomHitsTool > m_hitInputTool2
Gaudi::Property< bool > m_writePreClusterBranch
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_inputTruthParticleContainerKey
ToolHandle< GenericMonitoringTool > m_monTool
Gaudi::Property< bool > m_useInternalTruthTracks
std::atomic< unsigned long > m_nPixClusters
std::atomic< size_t > m_evt
ToolHandle< IFPGATrackSimEventInputHeaderTool > m_hitInputTool
FPGATrackSimLogicalEventInputHeader * m_logicEventHeader
std::atomic< unsigned > m_nMaxPixClusters
Gaudi::Property< int > m_writeRegion
SG::WriteHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey
std::string m_description
Gaudi::Property< int > m_clustering
std::atomic< unsigned long > m_nStripClusters
SG::WriteHandleKey< FPGATrackSimEventInfo > m_FPGAEventInfoKey
Gaudi::Property< bool > m_writeOutputData
SG::WriteHandleKeyArray< FPGATrackSimClusterCollection > m_FPGAClusterKey
ServiceHandle< IChronoStatSvc > m_chrono
ToolHandle< FPGATrackSimClusteringToolI > m_clusteringTool
FPGATrackSimDataPrepAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_doHitFiltering
Gaudi::Property< bool > m_recordHits
std::atomic< unsigned > m_ev
ToolHandle< IFPGATrackSimHitFilteringTool > m_hitFilteringTool
SG::WriteHandleKey< xAODTruthParticleLinkVector > m_truthLinkContainerKey
StatusCode readInputs(const EventContext &ctx, FPGATrackSimEventInputHeader &eventHeader, FPGATrackSimEventInputHeader &firstInputHeader, bool &done) const
const std::vector< FPGATrackSimTruthTrack > & getTruthTracks() const
const std::vector< FPGATrackSimOfflineTrack > & getOfflineTracks() const
a link optimized in size for a GenParticle in a McEventCollection
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
TruthParticle_v1 TruthParticle
Typedef to implementation.
constexpr bool enableBenchmark
std::pair< HepMcParticleLink, ElementLink< xAOD::TruthParticleContainer > > xAODTruthParticleLink