11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/ITHistSvc.h"
88 ATH_MSG_INFO(
"Hough constants method needs idealized geometry > 0, aborting.");
89 return StatusCode::FAILURE;
115 ATH_MSG_ERROR(
"q/pt bin information not set in matrix element job options!");
116 return StatusCode::FAILURE;
125 return StatusCode::SUCCESS;
179 m_h_trackQoP_okHits =
new TH1I(
"h_trackQoP_okHits",
"half inverse pt of tracks passing hit check",
181 m_h_trackQoP_okRegion =
new TH1I(
"h_trackQoP_okRegion",
"half inverse pt of tracks passing region check",
183 m_h_nHit =
new TH1I(
"h_nHit",
"number of hits in sector", 100, 0, 100);
189 return StatusCode::SUCCESS;
196 hists[i]->Fill(pars[i]);
214 std::vector<FPGATrackSimTruthTrack> truth_tracks =
m_eventHeader->optional().getTruthTracks();
217 if (tracks.empty()) {
219 return StatusCode::SUCCESS;
222 std::map<int, std::vector<FPGATrackSimHit>> barcode_hits =
makeBarcodeMap(hits, tracks);
230 std::vector<FPGATrackSimHit> & sector_hits = barcode_hits[track.getBarcode()];
236 for (
int iSlice = 0; iSlice<nSlices; iSlice++){
239 for (
auto & iHit : sector_hits) {
258 std::vector<std::shared_ptr<const FPGATrackSimRoad>> houghRoads;
261 std::vector<std::shared_ptr<const FPGATrackSimHit>> phits;
263 ATH_MSG_DEBUG(
"Starting from some number of sector hits = " << sector_hits.size());
264 for (
const FPGATrackSimHit& hit : sector_hits)
if (hit.isMapped() && hit.isReal()) phits.emplace_back(std::make_shared<const FPGATrackSimHit>(hit));
265 ATH_MSG_DEBUG(
"Passing nhits = " << phits.size() <<
" to road finder");
273 std::vector<FPGATrackSimTrack> tracks_1st;
279 ATH_MSG_DEBUG(
"We found " << tracks_1st.size() <<
" combinations");
281 for (
const auto& track_comb : tracks_1st) {
282 std::vector<FPGATrackSimHit> track_hits = track_comb.getFPGATrackSimHits();
289 std::vector<std::shared_ptr<const FPGATrackSimHit>> phits_2nd;
292 for (
const auto& hit : sector_hits) {
293 phits_2nd.push_back(std::make_shared<const FPGATrackSimHit>(hit));
297 std::vector<std::shared_ptr<const FPGATrackSimRoad>> roads_2nd;
298 std::vector<std::shared_ptr<const FPGATrackSimTrack>> ptracks_1st;
299 ptracks_1st.reserve(tracks_1st.size());
300 for (
const auto& track : tracks_1st) {
301 ptracks_1st.push_back(std::make_shared<const FPGATrackSimTrack>(track));
306 std::vector<FPGATrackSimTrack> tracks_2nd;
309 std::vector<FPGATrackSimHit> track_hits_2nd = track_2nd.getFPGATrackSimHits();
312 acc.pars.qOverPt = track_2nd.getHoughY();
313 acc.pars.phi = track_2nd.getHoughX();
316 std::vector<std::shared_ptr<const FPGATrackSimHit>> phits;
330 double y = track_comb.getHoughY();
331 double x = track_comb.getHoughX();
335 acc.pars.qOverPt =
y;
368 return StatusCode::SUCCESS;
376 std::vector<FPGATrackSimHit> hits;
389 std::vector<FPGATrackSimCluster> clustered_hits;
395 std::vector<FPGATrackSimCluster> spacepoints;
401 std::vector<FPGATrackSimTowerInputHeader> towers = logicalHeader.
towers();
402 for (
auto &tower : towers) {
403 std::vector<FPGATrackSimHit>
const & towerHits = tower.hits();
415 std::vector<FPGATrackSimTruthTrack> training_tracks;
422 if (!(
m_EvtSel->passMatching(track)))
continue;
424 double pt = TMath::Sqrt(track.getPX()*track.getPX() + track.getPY()*track.getPY());
425 double pt_GeV = pt / 1000;
432 double c = track.getQ() /(2 * pt);
433 double eta = TMath::ASinH(track.getPZ() / pt);
434 double phi = TMath::ATan2(track.getPY(), track.getPX());
439 <<
" pdgcode = " << track.getPDGCode());
444 return training_tracks;
451 std::map<int, std::vector<FPGATrackSimHit>>
map;
455 map[track.getBarcode()] = std::vector<FPGATrackSimHit>();
460 int barcode = hit.getTruth().best_barcode();
463 auto it =
map.find(barcode);
464 if (it !=
map.end()) (*it).second.push_back(hit);
503 if (old_section == new_section) {
509 rmax = phi_max - phi_min;
515 rmax = phi_max - phi_min;
541 old_disk =
m_FPGATrackSimMapping->PlaneMap_1st(subregion)->getLayerInfo(layer, old_section).physDisk;
542 new_disk =
m_FPGATrackSimMapping->PlaneMap_1st(subregion)->getLayerInfo(layer, new_section).physDisk;
547 old_disk =
m_FPGATrackSimMapping->PlaneMap_2nd(subregion)->getLayerInfo(layer, old_section).physDisk;
548 new_disk =
m_FPGATrackSimMapping->PlaneMap_2nd(subregion)->getLayerInfo(layer, new_section).physDisk;
551 if (old_isEC != new_isEC) {
557 else if (old_disk == new_disk) {
559 ATH_MSG_DEBUG(
"Two modules hit in same physical disk " << old_disk);
564 ATH_MSG_DEBUG(
"Keeping the lower-z of the two disks (" << old_disk <<
", " << new_disk <<
") hit");
584 sector_hits.resize(nLayers, nohit);
585 std::vector<int> layer_count(nLayers);
588 if (!hit.isReal() || !hit.isMapped())
continue;
592 if (rmap->getRegions(hit).size() == 0) {
595 int layer = hit.getLayer();
596 if (layer_count[layer] == 0){
597 layer_count[layer]++;
598 sector_hits[layer] = hit;
600 else if (layer_count[layer] == 1) {
601 layer_count[layer]++;
612 ATH_MSG_DEBUG(
"Too many hits on a plane, exiting filterHitsSec");
623 for (
int i = 0; i < nLayers; ++i)
625 if (layer_count[i] == 0)
635 if (sector_hits[i].isPixel()) {
642 ATH_MSG_DEBUG(
"Found " << num_sp <<
" spacepoints after removing duplicates.");
654 if (num_sp < minSpacePlusPixel) {
655 ATH_MSG_DEBUG(
"Not enough pixel hits + spacepoints (" << num_sp <<
" < " << minSpacePlusPixel <<
")");
667 std::vector<bool> region_mask(
m_nRegions,
true);
671 for (
int region = 0; region <
m_nRegions; region++) {
674 region_mask[region] =
false;
678 region_mask[region] =
false;
685 for (
int region = 0; region <
m_nRegions; region++) {
686 if (region_mask[region])
701 for (
auto module : modules) {
702 if (module == -1) nwc++;
706 for (
int layer = 0; layer < nLayers; layer++) {
711 ATH_MSG_DEBUG(
"Attempting to make wildcard in layer " << layer <<
", is1ststage = " << is1ststage);
718 sector_hits[layer] = *wcHit;
722 unsigned other_layer = 0;
724 other_layer = (backup_hit.
getPhysLayer() % 2 == 0) ? layer + 1 : layer - 1;
725 other_backup = sector_hits[other_layer];
735 if (
sc != StatusCode::SUCCESS){
737 ATH_MSG_ERROR(
"FPGATrackSimMatrixGenAlgo::fillAccumulatorByDropping; makeAccumulator failed");
738 return StatusCode::FAILURE;
740 accumulate(
map, new_modules_acc.first, new_modules_acc.second);
743 sector_hits[layer] = backup_hit;
748 sector_hits[other_layer] = other_backup;
752 return StatusCode::SUCCESS;
764 std::vector<module_t> modules(nLayers);
770 double qoverpt = track.getQ() / track.getPt();
782 std::string module_printout =
"";
783 for (
int i = 0; i < nLayers; i++)
785 if (sector_hits[i].isReal()) {
786 if (
m_single) modules[i] = sector_hits[i].getIdentifierHash();
788 modules[i] = sectorbin;
794 module_printout += std::to_string(modules[i]) +
", ";
802 ATH_MSG_DEBUG(
"Generating track in sectorbin = " << sectorbin <<
" with modules: " << module_printout);
806 const int ToKeep[13] = {2200,2564,2861,3831,5368,14169,14173,20442,20446,29625,29629,42176,42180};
807 bool keepThis =
true;
808 for (
int i = 0; i < 13; i++) {
809 if (modules[i] != ToKeep[i] && modules[i] != -1) {
815 for (
int i = 0; i < 13; i++) modules[i] = -1;
818 for (
int i = 0; i < 13; i++) {
825 double y = accumulator.second.pars.qOverPt;
826 double x = accumulator.second.pars.phi;
829 std::vector<float> coords;
831 for (
int i = 0; i < nLayers; ++i) {
833 if (sector_hits[i].isReal()) {
838 int other_layer = (sector_hits[i].getSide() == 0) ? i + 1 : i - 1;
844 std::vector<float> coords_tmp;
856 coords.push_back(coords_tmp[1]);
861 if (sector_hits[i].getDim() == 2 || (sector_hits[i].getHitType() ==
HitType::spacepoint && (sector_hits[i].getPhysLayer() % 2) == 1)) {
863 coords.push_back(coords_tmp[0]);
867 if (pmap->
getDim(i) == 2) {
874 assert(coords.size() == (
size_t)nDim);
875 acc.hit_coords = coords;
876 acc.hit_coordsG = coords;
879 acc.pars = track.getPars();
881 acc.pars.qOverPt = (
y / 1000.0) - track.getQOverPt();
882 acc.pars.phi =
x - track.getPhi();
888 acc.track_bins.push_back(
bins);
892 while (acc.pars.phi < 0) acc.pars.phi += 2*
M_PI;
893 while (acc.pars.phi > 2*
M_PI) acc.pars.phi -= 2*
M_PI;
897 for (
int i = 0; i < nDim; i++)
899 acc.hit_x_QoP[i] = coords[i] * acc.pars.qOverPt;
900 acc.hit_xG_HIP[i] = coords[i] * acc.pars.qOverPt;
901 acc.hit_x_d0[i] = coords[i] * acc.pars.d0;
902 acc.hit_x_z0[i] = coords[i] * acc.pars.z0;
903 acc.hit_x_eta[i] = coords[i] * acc.pars.eta;
904 acc.hit_xG_eta[i] = coords[i] * acc.pars.eta;
905 acc.hit_x_phi[i] = coords[i] * acc.pars.phi;
907 for (
int j = i; j < nDim; j++)
908 acc.covariance[i * nDim + j] = coords[i] * coords[j];
910 for (
int j = i; j < nDim; j++)
911 acc.covarianceG[i * nDim + j] = coords[i] * coords[j];
914 accumulator = {modules, acc};
915 return StatusCode::SUCCESS;
932 for (
int region = 0; region <
m_nRegions; region++) {
934 std::stringstream name;
935 std::stringstream title;
936 name <<
"am" << region;
937 title <<
"Ambank " << region <<
" parameters";
938 TTree*
tree =
new TTree(name.str().c_str(), title.str().c_str());
946 double coverage = sector_info.second.track_bins.size();
955 return StatusCode::SUCCESS;
961 TTree* sliceTree =
new TTree(
"slice",
"Region slice boundaries");
963 sliceTree->Branch(
"c_max", &
m_sliceMax.qOverPt);
965 sliceTree->Branch(
"phi_max", &
m_sliceMax.phi);
967 sliceTree->Branch(
"eta_max", &
m_sliceMax.eta);
969 sliceTree->Branch(
"c_min", &
m_sliceMin.qOverPt);
971 sliceTree->Branch(
"phi_min", &
m_sliceMin.phi);
973 sliceTree->Branch(
"eta_min", &
m_sliceMin.eta);
975 sliceTree->Branch(
"c_slices", &
m_nBins.qOverPt);
976 sliceTree->Branch(
"d0_slices", &
m_nBins.d0);
977 sliceTree->Branch(
"phi_slices", &
m_nBins.phi);
978 sliceTree->Branch(
"z0_slices", &
m_nBins.z0);
979 sliceTree->Branch(
"eta_slices", &
m_nBins.eta);
981 StatusCode
sc =
m_tHistSvc->regTree(
"/TRIGFPGATrackSimMATRIXOUT/slice",sliceTree);
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::vector< float > computeIdealCoords(const FPGATrackSimHit &hit, const double hough_x, const double hough_y, const double target_r, const bool doDeltaGPhis, const TrackCorrType trackCorrType)
void roadsToTrack(std::vector< std::shared_ptr< const FPGATrackSimRoad > > &roads, std::vector< FPGATrackSimTrack > &track_cands, const FPGATrackSimPlaneMap *pmap)
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Helper struct for accumulating sector information for matrix generation.
std::unordered_map< std::vector< module_t >, FPGATrackSimMatrixAccumulator, container_hash< std::vector< module_t > > > AccumulateMap
void fillTrackPars(TH1I *const hists[FPGATrackSimTrackPars::NPARS], FPGATrackSimTruthTrack const &track)
Algorithm to generate matrix files, to be used for sector and constant generation.
void fillTree(AccumulateMap &map, TTree *tree, int nLayers, int nCoords)
Writes the contents of an AccumulateMap into the supplied tree (one entry per sector).
Stores slice definitions for FPGATrackSim regions.
static const std::vector< std::string > bins
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
bool msgLvl(const MSG::Level lvl) const
void setLayer(unsigned v)
void setHitType(HitType type)
int getEtaModule(bool old=false) const
unsigned getPhiModule() const
unsigned getPhysLayer(bool old=false) const
const FPGATrackSimHit getOriginalHit() const
unsigned getSection() const
HitType getHitType() const
void setDetType(SiliconTech detType)
Gaudi::Property< int > m_ideal_geom
ToolHandle< FPGATrackSimRawToLogicalHitsTool > m_hitMapTool
std::map< int, std::vector< FPGATrackSimHit > > makeBarcodeMap(std::vector< FPGATrackSimHit > const &hits, std::vector< FPGATrackSimTruthTrack > const &tracks) const
Gaudi::Property< float > m_temp_c_max
FPGATrackSimMatrixGenAlgo(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_doDeltaPhiConsts
StatusCode initialize() override
StatusCode bookHistograms()
Gaudi::Property< float > m_temp_d0_max
Gaudi::Property< bool > m_single
TH1I * m_h_trackQoP_okRegion
const FPGATrackSimPlaneMap * m_pmap_2nd
std::vector< FPGATrackSimTruthTrack > filterTrainingTracks(std::vector< FPGATrackSimTruthTrack > const &truth_tracks) const
Gaudi::Property< std::vector< double > > m_qOverPtBins
Gaudi::Property< float > m_temp_phi_max
Gaudi::Property< int > m_temp_z0_slices
Gaudi::Property< float > m_PT_THRESHOLD
Gaudi::Property< int > m_temp_d0_slices
Gaudi::Property< int > m_temp_eta_slices
TH1I * m_h_trainingTrack[FPGATrackSimTrackPars::NPARS]
Gaudi::Property< int > m_temp_phi_slices
ToolHandle< FPGATrackSimRoadUnionTool > m_roadFinderTool
Gaudi::Property< float > m_temp_c_min
Gaudi::Property< float > m_temp_z0_max
Gaudi::Property< float > m_temp_eta_min
FPGATrackSimTrackParsI m_nBins
Gaudi::Property< float > m_D0_THRESHOLD
Gaudi::Property< bool > m_doSpacePoints
Gaudi::Property< int > m_TRAIN_PDG
Gaudi::Property< bool > m_absQOverPtBinning
FPGATrackSimTrackPars m_sliceMin
Gaudi::Property< float > m_temp_phi_min
Gaudi::Property< float > m_temp_z0_min
StatusCode makeAccumulator(std::vector< FPGATrackSimHit > const §or_hits, FPGATrackSimTruthTrack const &track, std::pair< std::vector< module_t >, FPGATrackSimMatrixAccumulator > &accumulator) const
ToolHandle< FPGATrackSimClusteringToolI > m_clusteringTool
ToolHandle< FPGATrackSimOverlapRemovalTool > m_overlapRemovalTool
TH1I * m_h_trackQoP_okHits
StatusCode finalize() override
Gaudi::Property< bool > m_doClustering
FPGATrackSimTrackPars m_sliceMax
TH1I * m_h_notEnoughHits[FPGATrackSimTrackPars::NPARS]
Gaudi::Property< int > m_minSpacePlusPixel
const FPGATrackSimPlaneMap * m_pmap_1st
TH1I * m_h_sectorPars[FPGATrackSimTrackPars::NPARS]
std::vector< FPGATrackSimHit > getLogicalHits()
TH1I * m_h_3hitsInLayer[FPGATrackSimTrackPars::NPARS]
FPGATrackSimEventInputHeader * m_eventHeader
ToolHandle< FPGATrackSimTrackFitterTool > m_trackFitterTool_1st
ServiceHandle< ITHistSvc > m_tHistSvc
selectHit_returnCode selectHit(FPGATrackSimHit const &old_hit, FPGATrackSimHit const &new_hit, bool is1ststage, int subregion) const
StatusCode execute() override
std::vector< AccumulateMap > m_sector_cum
StatusCode fillAccumulatorByDropping(std::vector< FPGATrackSimHit > §or_hits, bool is1ststage, double x, double y, std::vector< module_t > &modules, AccumulateMap &map, FPGATrackSimTruthTrack const &track, int subregion) const
Gaudi::Property< float > m_temp_d0_min
Gaudi::Property< int > m_nRegions
Gaudi::Property< bool > m_dropHitsAndFill
Gaudi::Property< int > m_temp_c_slices
ToolHandle< IFPGATrackSimTrackExtensionTool > m_trackExtensionTool
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Gaudi::Property< bool > m_doHoughConstants
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
int getRegion(std::vector< FPGATrackSimHit > const &hits, bool is1ststage) const
bool filterSectorHits(std::vector< FPGATrackSimHit > const &all_hits, std::vector< FPGATrackSimHit > §or_hits, FPGATrackSimTruthTrack const &t, bool is1ststage, int subregion) const
Gaudi::Property< float > m_temp_eta_max
TH1I * m_h_SHfailure[FPGATrackSimTrackPars::NPARS]
Gaudi::Property< int > m_MaxWC
ToolHandle< FPGATrackSimSpacePointsToolI > m_spacePointsTool
Gaudi::Property< bool > m_doSecondStage
ToolHandle< IFPGATrackSimInputTool > m_hitInputTool
uint32_t getDim(size_t logiLayer) const
void map(FPGATrackSimHit &hit) const
static std::string parName(unsigned i)
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
constexpr int QPT_SECTOR_OFFSET
constexpr int SPACEPOINT_SECTOR_OFFSET
FPGATrackSimTrackPars pars