ATLAS Offline Software
TgcDataPreparator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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  TrigL2MuonSA::TgcHits& tgcHits) const
27 {
28  float roi_eta = p_roi->eta();
29  float roi_phi = p_roi->phi();
30  if (roi_phi < 0) roi_phi += 2.0 * M_PI;
31 
32  //const Muon::TgcPrepDataContainer* tgcPrepContainer = 0;
33  const Muon::TgcPrepDataContainer* tgcPrepContainer;
34  int gasGap;
35  int channel;
36 
37  const bool isLowPt = m_recMuonRoIUtils.isLowPt(p_roi);
38 
39  // Select the eta cut based on ROI Pt.
40  const double mid_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtMiddleForLowPt()
41  : m_options.roadParameters().deltaEtaAtMiddleForHighPt();
42  const double inn_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtInnerForLowPt()
43  : m_options.roadParameters().deltaEtaAtInnerForHighPt();
44  const double mid_phi_test = m_options.roadParameters().deltaPhiAtMiddle();
45  const double inn_phi_test = m_options.roadParameters().deltaPhiAtInner();
46 
47  auto tgcContainerHandle = SG::makeHandle(m_tgcContainerKey);
48  tgcPrepContainer = tgcContainerHandle.cptr();
49  if (!tgcContainerHandle.isValid()) {
50  ATH_MSG_ERROR("Could not retrieve PrepDataContainer key:" << m_tgcContainerKey.key());
51  return StatusCode::FAILURE;
52  } else {
53  ATH_MSG_DEBUG("Retrieved PrepDataContainer: " << tgcPrepContainer->numberOfCollections());
54  }
55 
56  //Find closest wires in Middle
57  float min_dphi_wire=1000.;
58  float second_dphi_wire=1000.;
59  std::vector<float> ov_dphi;
60  ov_dphi.clear();
61  for( const Muon::TgcPrepDataCollection* wi : *tgcPrepContainer ) { // loop over collections
62  if( !wi ) continue;
63  for( const Muon::TgcPrepData* cwi : *wi ){ // loop over data in the collection
64  if( !cwi ) continue;
65  const Muon::TgcPrepData& prepDataWi = *cwi;
66  if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataWi.identify())) {//wire
67  int stationNumWi = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataWi.identify())-1;
68  if (stationNumWi==-1) stationNumWi=3;
69  if (stationNumWi<3 && std::abs(prepDataWi.globalPosition().eta() - roi_eta) < mid_eta_test ) {
70  const float dphi = std::acos(std::cos(prepDataWi.globalPosition().phi()-roi_phi));
71  bool overlap=false;
72  for (unsigned int ov=0;ov<ov_dphi.size();ov++)
73  if (std::abs(dphi-ov_dphi[ov])<1e-5) overlap=true;
74  if (overlap) continue;
75  ov_dphi.push_back(dphi);
76  if (dphi<second_dphi_wire){
77  second_dphi_wire=dphi;
78  }
79  if (dphi<min_dphi_wire) {
80  second_dphi_wire=min_dphi_wire;
81  min_dphi_wire=dphi;
82  }
83  }
84  }
85  }
86  }
87 
88  //Check if there are enough number of hits
89  int num_min_hits=0;
90  int num_second_hits=0;
91  for( const Muon::TgcPrepDataCollection* hit : *tgcPrepContainer ) { // loop over collections
92  if( !hit ) continue;
93  for( const Muon::TgcPrepData* chit : *hit ){ // loop over data in the collection
94  if( !chit ) continue;
95  const Muon::TgcPrepData& prepDataHit = *chit;
96  if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataHit.identify())) {//strip
97  int stationNumHit = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataHit.identify())-1;
98  if (stationNumHit==-1) stationNumHit=3;
99  if (stationNumHit<3 && std::abs(prepDataHit.globalPosition().eta() - roi_eta) < mid_eta_test ) {
100  const float dphi = std::acos(std::cos(prepDataHit.globalPosition().phi()-roi_phi));
101  if (std::abs(dphi-min_dphi_wire)<1e-5) num_min_hits++;
102  if (std::abs(dphi-second_dphi_wire)<1e-5) num_second_hits++;
103  }
104  }
105  }
106  }
107 
108  float dphi_wire=min_dphi_wire;
109  bool useDefault=false;
110  if (num_min_hits<5) {
111  if (num_second_hits>5) dphi_wire=second_dphi_wire;
112  else useDefault=true;
113  }
114 
115  for( const Muon::TgcPrepDataCollection* col : *tgcPrepContainer ) { // loop over collections
116  if( !col ) continue;
117  for( const Muon::TgcPrepData* cit : *col ){ // loop over data in the collection
118  if( !cit ) continue;
119  const Muon::TgcPrepData& prepData = *cit;
120 
121  bool isInRoad = false;
122  int stationNum = m_idHelperSvc->tgcIdHelper().stationRegion(prepData.identify())-1;
123  if (stationNum==-1) stationNum=3;
124  if (m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())) {
125  double dphi = std::abs(prepData.globalPosition().phi() - roi_phi);
126  if( dphi > M_PI*2 ) dphi = dphi - M_PI*2;
127  if( dphi > M_PI ) dphi = M_PI*2 - dphi;
128  // For strips, apply phi cut
129  if ( stationNum < 3 && dphi < mid_phi_test ) { isInRoad = true; }
130  else if( stationNum == 3 && dphi < inn_phi_test ) { isInRoad = true; }
131  }
132  else {
133  // For wires, apply eta cut.
134  const float dphi = std::acos(std::cos(prepData.globalPosition().phi()-roi_phi));
135  if ( stationNum < 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < mid_eta_test ) {
136  if (useDefault) isInRoad = true;//default
137  else if (std::abs(dphi-dphi_wire)<1e-5) isInRoad = true;//for close-by muon
138  }
139  else if( stationNum == 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < inn_eta_test ) { isInRoad = true; }
140  }
141  if( ! isInRoad ) continue;
142 
143  const MuonGM::TgcReadoutElement* tgcReadout = prepData.detectorElement();
144  gasGap = m_idHelperSvc->tgcIdHelper().gasGap(prepData.identify());
145  channel = m_idHelperSvc->tgcIdHelper().channel(prepData.identify());
146 
147  TrigL2MuonSA::TgcHitData lutDigit;
148 
149  lutDigit.eta = prepData.globalPosition().eta();
150  lutDigit.phi = prepData.globalPosition().phi();
151  lutDigit.r = prepData.globalPosition().perp();
152  lutDigit.z = prepData.globalPosition().z();
153  lutDigit.sta = stationNum;
154  lutDigit.isStrip = m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify());
155  if(m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())){
156  lutDigit.width = tgcReadout->stripWidth(gasGap, channel);
157  }
158  else{
159  lutDigit.width = tgcReadout->gangRadialLength(gasGap, channel);
160  }
161  lutDigit.bcTag = 2;
162  lutDigit.inRoad = false;
163 
164 
165  tgcHits.push_back(lutDigit);
166 
167  }
168  }
169 
170  return StatusCode::SUCCESS;
171 }
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
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:61
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:53
TgcDataPreparator.h
TgcData.h
TrigL2MuonSA::TgcDataPreparator::prepareData
StatusCode prepareData(const xAOD::MuonRoI *p_roi, TrigL2MuonSA::TgcHits &tgcHits) const
Definition: TgcDataPreparator.cxx:25
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.