26#include "GaudiKernel/IEventProcessor.h"
30#ifdef BENCHMARK_FPGATRACKSIM
51 while (std::getline(
ss, line,
'\n')) {
57 const std::vector<Gaudi::Details::PropertyBase*> props = this->getProperties();
58 for( Gaudi::Details::PropertyBase* prop : props ) {
59 if (prop->ownerTypeName()==this->type()) {
60 ATH_MSG_DEBUG(
"Property:\t" << prop->name() <<
"\t : \t" << prop->toString());
99 return StatusCode::SUCCESS;
118 std::vector<std::unique_ptr<FPGATrackSimHit>> hits_miss;
125 SmartIF<IEventProcessor> appMgr{service(
"ApplicationMgr")};
127 ATH_MSG_ERROR(
"Failed to retrieve ApplicationMgr as IEventProcessor");
128 return StatusCode::FAILURE;
130 return appMgr->stopRun();
137 ATH_CHECK( FPGAHitUnmapped.
record (std::make_unique<FPGATrackSimHitCollection>()));
140 ATH_CHECK( FPGAClusters.
record (std::make_unique<FPGATrackSimClusterCollection>()));
143 ATH_CHECK(truthLinkVec.
record(std::make_unique<xAODTruthParticleLinkVector>()));
146 ATH_CHECK(FPGATruthTracks.
record(std::make_unique<FPGATrackSimTruthTrackCollection>()));
149 ATH_CHECK(FPGAOfflineTracks.
record(std::make_unique<FPGATrackSimOfflineTrackCollection>()));
152 bool acceptEvent =
false;
156 if (eventSelector->selectEvent(eventHeader)) {
157 ATH_MSG_DEBUG(
"Event accepted by: " << eventSelector->name());
168 if (!truthParticleContainer.
isValid()) {
169 ATH_MSG_ERROR(
"No valid truth particle container with key " << truthParticleContainer.
key());
170 return StatusCode::FAILURE;
173 std::unordered_map<HepMcParticleLink::barcode_type, std::pair<const xAOD::TruthParticle*, size_t>> truthParticlesMap;
174 size_t truthParticleIndex = 0;
176 truthParticlesMap.insert(std::make_pair(
HepMC::uniqueID(truthParticle), std::make_pair(truthParticle,truthParticleIndex)));
177 truthParticleIndex++;
180 truthLinkVec->reserve(fpgaTruthTracks.size());
181 ATH_MSG_DEBUG(
"begin truth matching for " << fpgaTruthTracks.size() <<
" FPGA truth tracks");
183 auto it = truthParticlesMap.find(fpgaTruthTrack.getUniqueID());
184 if (it != truthParticlesMap.end()) {
192 if (truthLinkVec->empty()) {
193 ATH_MSG_DEBUG(
"No truth particles selected. Skipping event...");
194 return StatusCode::SUCCESS;
203 eventSelector->setSelectedEvent(
true);
212 hits_miss, clusters, FPGAHitUnmapped, FPGAClusters));
216 FPGATruthTracks->push_back(truthtrack);
221 FPGAOfflineTracks->push_back(offlineTrack);
232 const unsigned& regionID = eventSelector->getRegionID();
238 std::vector<FPGATrackSimHit>
const& hits = logicEventHeader.
towers().at(0).hits();
242 auto *FPGAHits_cdv = FPGAHits.
ptr();
245 if (hit->
isReal()) FPGAHits_cdv->push_back(hit);
273 return StatusCode::SUCCESS;
282 const EventContext& ctx,
291 return StatusCode::SUCCESS;
300 ATH_MSG_DEBUG(
"Cannot read more events from file, returning");
301 return StatusCode::SUCCESS;
305 eventHeader = firstInputHeader;
313 ATH_MSG_INFO(
"Cannot read more events from file, returning");
314 return StatusCode::SUCCESS;
320 return StatusCode::SUCCESS;
329 std::vector<std::unique_ptr<FPGATrackSimHit>>& hits_miss,
336 logicEventHeader.
reset();
337 logicEventHeader_precluster.
reset();
341 ATH_CHECK(hitMapTool->convert(1, eventHeader, logicEventHeader));
346 for (
auto& hit : hits_miss) FPGAHitUnmapped->push_back(std::move(hit));
350 ATH_MSG_DEBUG(
"Hits conversion done, #unmapped hists = " << FPGAHitUnmapped->size());
354 logicEventHeader_precluster = logicEventHeader;
364 unsigned npix(0), nstrip(0);
366 if (cluster.getClusterEquiv().isPixel()) npix++;
383 while (npix > current_max_pix &&
388 while (nstrip > current_max_strip &&
393 unsigned clusters_size = clusters.size();
394 while (clusters_size > current_max_clusters &&
395 !
m_nMaxClusters.compare_exchange_weak(current_max_clusters, clusters_size));
398 FPGAClusters->insert(
400 std::make_move_iterator(clusters.begin()),
401 std::make_move_iterator(clusters.end()));
405 return StatusCode::SUCCESS;
413 ATH_MSG_INFO(
"PRINTING FPGATRACKSIM SIMPLE DATAPREP STATS");
414 ATH_MSG_INFO(
"========================================================================================");
421 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
DataVector adapter that acts like it holds const pointers.
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
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
An algorithm that can be simultaneously executed in multiple threads.
DataVector adapter that acts like it holds const pointers.
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
SG::WriteHandleKey< ConstDataVector< FPGATrackSimHitCollection > > m_FPGAHitKey
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
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.
pointer_type ptr()
Dereference the pointer.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
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