ATLAS Offline Software
Loading...
Searching...
No Matches
TgcDataPreparator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TgcDataPreparator.h"
6#include "TgcData.h"
7#include "RecMuonRoIUtils.h"
9
10// --------------------------------------------------------------------------------
11// --------------------------------------------------------------------------------
12
14{
15 ATH_CHECK(m_idHelperSvc.retrieve());
16
17 ATH_CHECK(m_tgcContainerKey.initialize());
18
19 return StatusCode::SUCCESS;
20}
21
22// --------------------------------------------------------------------------------
23// --------------------------------------------------------------------------------
24
25StatusCode TrigL2MuonSA::TgcDataPreparator::prepareData(const EventContext& ctx,
26 const xAOD::MuonRoI* p_roi,
27 TrigL2MuonSA::TgcHits& tgcHits) const
28{
29 float roi_eta = p_roi->eta();
30 float roi_phi = p_roi->phi();
31 if (roi_phi < 0) roi_phi += 2.0 * M_PI;
32
33 //const Muon::TgcPrepDataContainer* tgcPrepContainer = 0;
34 const Muon::TgcPrepDataContainer* tgcPrepContainer;
35 int gasGap;
36 int channel;
37
38 const bool isLowPt = m_recMuonRoIUtils.isLowPt(p_roi);
39
40 // Select the eta cut based on ROI Pt.
41 const double mid_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtMiddleForLowPt()
42 : m_options.roadParameters().deltaEtaAtMiddleForHighPt();
43 const double inn_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtInnerForLowPt()
44 : m_options.roadParameters().deltaEtaAtInnerForHighPt();
45 const double mid_phi_test = m_options.roadParameters().deltaPhiAtMiddle();
46 const double inn_phi_test = m_options.roadParameters().deltaPhiAtInner();
47
48 auto tgcContainerHandle = SG::makeHandle(m_tgcContainerKey, ctx);
49 tgcPrepContainer = tgcContainerHandle.cptr();
50 if (!tgcContainerHandle.isValid()) {
51 ATH_MSG_ERROR("Could not retrieve PrepDataContainer key:" << m_tgcContainerKey.key());
52 return StatusCode::FAILURE;
53 } else {
54 ATH_MSG_DEBUG("Retrieved PrepDataContainer: " << tgcPrepContainer->numberOfCollections());
55 }
56
57 //Find closest wires in Middle
58 float min_dphi_wire=1000.;
59 float second_dphi_wire=1000.;
60 std::vector<float> ov_dphi;
61 ov_dphi.clear();
62 for( const Muon::TgcPrepDataCollection* wi : *tgcPrepContainer ) { // loop over collections
63 if( !wi ) continue;
64 for( const Muon::TgcPrepData* cwi : *wi ){ // loop over data in the collection
65 if( !cwi ) continue;
66 const Muon::TgcPrepData& prepDataWi = *cwi;
67 if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataWi.identify())) {//wire
68 int stationNumWi = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataWi.identify())-1;
69 if (stationNumWi==-1) stationNumWi=3;
70 if (stationNumWi<3 && std::abs(prepDataWi.globalPosition().eta() - roi_eta) < mid_eta_test ) {
71 const float dphi = std::acos(std::cos(prepDataWi.globalPosition().phi()-roi_phi));
72 bool overlap=false;
73 for (unsigned int ov=0;ov<ov_dphi.size();ov++)
74 if (std::abs(dphi-ov_dphi[ov])<1e-5) overlap=true;
75 if (overlap) continue;
76 ov_dphi.push_back(dphi);
77 if (dphi<second_dphi_wire){
78 second_dphi_wire=dphi;
79 }
80 if (dphi<min_dphi_wire) {
81 second_dphi_wire=min_dphi_wire;
82 min_dphi_wire=dphi;
83 }
84 }
85 }
86 }
87 }
88
89 //Check if there are enough number of hits
90 int num_min_hits=0;
91 int num_second_hits=0;
92 for( const Muon::TgcPrepDataCollection* hit : *tgcPrepContainer ) { // loop over collections
93 if( !hit ) continue;
94 for( const Muon::TgcPrepData* chit : *hit ){ // loop over data in the collection
95 if( !chit ) continue;
96 const Muon::TgcPrepData& prepDataHit = *chit;
97 if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataHit.identify())) {//strip
98 int stationNumHit = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataHit.identify())-1;
99 if (stationNumHit==-1) stationNumHit=3;
100 if (stationNumHit<3 && std::abs(prepDataHit.globalPosition().eta() - roi_eta) < mid_eta_test ) {
101 const float dphi = std::acos(std::cos(prepDataHit.globalPosition().phi()-roi_phi));
102 if (std::abs(dphi-min_dphi_wire)<1e-5) num_min_hits++;
103 if (std::abs(dphi-second_dphi_wire)<1e-5) num_second_hits++;
104 }
105 }
106 }
107 }
108
109 float dphi_wire=min_dphi_wire;
110 bool useDefault=false;
111 if (num_min_hits<5) {
112 if (num_second_hits>5) dphi_wire=second_dphi_wire;
113 else useDefault=true;
114 }
115
116 for( const Muon::TgcPrepDataCollection* col : *tgcPrepContainer ) { // loop over collections
117 if( !col ) continue;
118 for( const Muon::TgcPrepData* cit : *col ){ // loop over data in the collection
119 if( !cit ) continue;
120 const Muon::TgcPrepData& prepData = *cit;
121
122 bool isInRoad = false;
123 int stationNum = m_idHelperSvc->tgcIdHelper().stationRegion(prepData.identify())-1;
124 if (stationNum==-1) stationNum=3;
125 if (m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())) {
126 double dphi = std::abs(prepData.globalPosition().phi() - roi_phi);
127 if( dphi > M_PI*2 ) dphi = dphi - M_PI*2;
128 if( dphi > M_PI ) dphi = M_PI*2 - dphi;
129 // For strips, apply phi cut
130 if ( stationNum < 3 && dphi < mid_phi_test ) { isInRoad = true; }
131 else if( stationNum == 3 && dphi < inn_phi_test ) { isInRoad = true; }
132 }
133 else {
134 // For wires, apply eta cut.
135 const float dphi = std::acos(std::cos(prepData.globalPosition().phi()-roi_phi));
136 if ( stationNum < 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < mid_eta_test ) {
137 if (useDefault) isInRoad = true;//default
138 else if (std::abs(dphi-dphi_wire)<1e-5) isInRoad = true;//for close-by muon
139 }
140 else if( stationNum == 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < inn_eta_test ) { isInRoad = true; }
141 }
142 if( ! isInRoad ) continue;
143
144 const MuonGM::TgcReadoutElement* tgcReadout = prepData.detectorElement();
145 gasGap = m_idHelperSvc->tgcIdHelper().gasGap(prepData.identify());
146 channel = m_idHelperSvc->tgcIdHelper().channel(prepData.identify());
147
149
150 lutDigit.eta = prepData.globalPosition().eta();
151 lutDigit.phi = prepData.globalPosition().phi();
152 lutDigit.r = prepData.globalPosition().perp();
153 lutDigit.z = prepData.globalPosition().z();
154 lutDigit.sta = stationNum;
155 lutDigit.isStrip = m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify());
156 if(m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())){
157 lutDigit.width = tgcReadout->stripWidth(gasGap, channel);
158 }
159 else{
160 lutDigit.width = tgcReadout->gangRadialLength(gasGap, channel);
161 }
162 lutDigit.bcTag = 2;
163 lutDigit.inRoad = false;
164
165
166 tgcHits.push_back(lutDigit);
167
168 }
169 }
170
171 return StatusCode::SUCCESS;
172}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
virtual size_t numberOfCollections() const override final
return number of collections
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
double stripWidth(int gasGap, int strip) const
Returns the width of a given strip in the gasGap i.
double gangRadialLength(int gasGap, int gang) const
Returns the length of the wire gang along the radial direction [pitch x N_{wire}^{gang}...
Class to represent TGC measurements.
Definition TgcPrepData.h:32
virtual const Amg::Vector3D & globalPosition() const override final
Returns the global position.
virtual const MuonGM::TgcReadoutElement * detectorElement() const override final
Returns the detector element corresponding to this PRD The pointer will be zero if the det el is not ...
TrigL2MuonSA::RecMuonRoIUtils m_recMuonRoIUtils
SG::ReadHandleKey< Muon::TgcPrepDataContainer > m_tgcContainerKey
TrigL2MuonSA::TgcDataPreparatorOptions m_options
virtual StatusCode initialize() override
StatusCode prepareData(const EventContext &ctx, const xAOD::MuonRoI *p_roi, TrigL2MuonSA::TgcHits &tgcHits) const
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Identifier identify() const
return the identifier
float eta() const
The pseudorapidity ( ) of the muon candidate.
float phi() const
The azimuthal angle ( ) of the muon candidate.
MuonPrepDataCollection< TgcPrepData > TgcPrepDataCollection
MuonPrepDataContainerT< TgcPrepData > TgcPrepDataContainer
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
std::vector< TgcHitData > TgcHits
Definition TgcData.h:43
MuonRoI_v1 MuonRoI
Definition MuonRoI.h:15