ATLAS Offline Software
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 
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 
148  TrigL2MuonSA::TgcHitData lutDigit;
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 }
ReadFromCoolCompare.ov
ov
Definition: ReadFromCoolCompare.py:230
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
TrigL2MuonSA::TgcHitData::sta
int sta
Definition: TgcData.h:34
TrigL2MuonSA::TgcHitData::phi
double phi
Definition: TgcData.h:30
TrigL2MuonSA::TgcHits
std::vector< TgcHitData > TgcHits
Definition: TgcData.h:43
M_PI
#define M_PI
Definition: ActiveFraction.h:11
xAOD::MuonRoI_v1::eta
float eta() const
The pseudorapidity ( ) of the muon candidate.
Muon::TgcPrepData::detectorElement
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 ...
Definition: TgcPrepData.h:119
TrigL2MuonSA::TgcDataPreparator::prepareData
StatusCode prepareData(const EventContext &ctx, const xAOD::MuonRoI *p_roi, TrigL2MuonSA::TgcHits &tgcHits) const
Definition: TgcDataPreparator.cxx:25
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
MuonPrepDataContainer.h
TrigL2MuonSA::TgcHitData::isStrip
bool isStrip
Definition: TgcData.h:35
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
RecMuonRoIUtils.h
TrigL2MuonSA::TgcDataPreparator::initialize
virtual StatusCode initialize() override
Definition: TgcDataPreparator.cxx:13
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonGM::TgcReadoutElement::stripWidth
double stripWidth(int gasGap, int strip) const
Returns the width of a given strip in the gasGap i.
Definition: MuonDetDescr/MuonReadoutGeometry/src/TgcReadoutElement.cxx:152
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::MuonRoI_v1
Class describing a LVL1 muon region of interest.
Definition: MuonRoI_v1.h:29
MuonGM::TgcReadoutElement
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/TgcReadoutElement.h:42
TrigL2MuonSA::TgcDataPreparator::m_tgcContainerKey
SG::ReadHandleKey< Muon::TgcPrepDataContainer > m_tgcContainerKey
Definition: TgcDataPreparator.h:62
MuonGM::TgcReadoutElement::gangRadialLength
double gangRadialLength(int gasGap, int gang) const
Returns the length of the wire gang along the radial direction [pitch x N_{wire}^{gang}].
Definition: MuonDetDescr/MuonReadoutGeometry/src/TgcReadoutElement.cxx:72
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigL2MuonSA::TgcHitData
Definition: TgcData.h:14
TrigL2MuonSA::TgcHitData::width
double width
Definition: TgcData.h:33
TrigL2MuonSA::TgcHitData::r
double r
Definition: TgcData.h:31
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
TrigL2MuonSA::TgcDataPreparator::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: TgcDataPreparator.h:54
TgcDataPreparator.h
TgcData.h
TrigL2MuonSA::TgcHitData::z
double z
Definition: TgcData.h:32
TrigL2MuonSA::TgcHitData::bcTag
int bcTag
Definition: TgcData.h:36
Muon::TgcPrepData
Class to represent TGC measurements.
Definition: TgcPrepData.h:32
Muon::TgcPrepData::globalPosition
virtual const Amg::Vector3D & globalPosition() const override final
Returns the global position.
Definition: TgcPrepData.h:124
TrigL2MuonSA::TgcHitData::eta
double eta
Definition: TgcData.h:26
TrigL2MuonSA::TgcHitData::inRoad
bool inRoad
Definition: TgcData.h:37
xAOD::MuonRoI_v1::phi
float phi() const
The azimuthal angle ( ) of the muon candidate.