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  const std::string& name,
15  const IInterface* parent):
17 {
18 }
19 
20 // --------------------------------------------------------------------------------
21 // --------------------------------------------------------------------------------
22 
24 {
25  ATH_CHECK(m_idHelperSvc.retrieve());
26 
27  ATH_CHECK(m_tgcContainerKey.initialize());
28 
29  return StatusCode::SUCCESS;
30 }
31 
32 // --------------------------------------------------------------------------------
33 // --------------------------------------------------------------------------------
34 
36  TrigL2MuonSA::TgcHits& tgcHits) const
37 {
38  float roi_eta = p_roi->eta();
39  float roi_phi = p_roi->phi();
40  if (roi_phi < 0) roi_phi += 2.0 * M_PI;
41 
42  //const Muon::TgcPrepDataContainer* tgcPrepContainer = 0;
43  const Muon::TgcPrepDataContainer* tgcPrepContainer;
44  int gasGap;
45  int channel;
46 
47  const bool isLowPt = m_recMuonRoIUtils.isLowPt(p_roi);
48 
49  // Select the eta cut based on ROI Pt.
50  const double mid_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtMiddleForLowPt()
51  : m_options.roadParameters().deltaEtaAtMiddleForHighPt();
52  const double inn_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtInnerForLowPt()
53  : m_options.roadParameters().deltaEtaAtInnerForHighPt();
54  const double mid_phi_test = m_options.roadParameters().deltaPhiAtMiddle();
55  const double inn_phi_test = m_options.roadParameters().deltaPhiAtInner();
56 
57  auto tgcContainerHandle = SG::makeHandle(m_tgcContainerKey);
58  tgcPrepContainer = tgcContainerHandle.cptr();
59  if (!tgcContainerHandle.isValid()) {
60  ATH_MSG_ERROR("Could not retrieve PrepDataContainer key:" << m_tgcContainerKey.key());
61  return StatusCode::FAILURE;
62  } else {
63  ATH_MSG_DEBUG("Retrieved PrepDataContainer: " << tgcPrepContainer->numberOfCollections());
64  }
65 
66  //Find closest wires in Middle
67  float min_dphi_wire=1000.;
68  float second_dphi_wire=1000.;
69  std::vector<float> ov_dphi;
70  ov_dphi.clear();
71  for( const Muon::TgcPrepDataCollection* wi : *tgcPrepContainer ) { // loop over collections
72  if( !wi ) continue;
73  for( const Muon::TgcPrepData* cwi : *wi ){ // loop over data in the collection
74  if( !cwi ) continue;
75  const Muon::TgcPrepData& prepDataWi = *cwi;
76  if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataWi.identify())) {//wire
77  int stationNumWi = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataWi.identify())-1;
78  if (stationNumWi==-1) stationNumWi=3;
79  if (stationNumWi<3 && std::abs(prepDataWi.globalPosition().eta() - roi_eta) < mid_eta_test ) {
80  const float dphi = std::acos(std::cos(prepDataWi.globalPosition().phi()-roi_phi));
81  bool overlap=false;
82  for (unsigned int ov=0;ov<ov_dphi.size();ov++)
83  if (std::abs(dphi-ov_dphi[ov])<1e-5) overlap=true;
84  if (overlap) continue;
85  ov_dphi.push_back(dphi);
86  if (dphi<second_dphi_wire){
87  second_dphi_wire=dphi;
88  }
89  if (dphi<min_dphi_wire) {
90  second_dphi_wire=min_dphi_wire;
91  min_dphi_wire=dphi;
92  }
93  }
94  }
95  }
96  }
97 
98  //Check if there are enough number of hits
99  int num_min_hits=0;
100  int num_second_hits=0;
101  for( const Muon::TgcPrepDataCollection* hit : *tgcPrepContainer ) { // loop over collections
102  if( !hit ) continue;
103  for( const Muon::TgcPrepData* chit : *hit ){ // loop over data in the collection
104  if( !chit ) continue;
105  const Muon::TgcPrepData& prepDataHit = *chit;
106  if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataHit.identify())) {//strip
107  int stationNumHit = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataHit.identify())-1;
108  if (stationNumHit==-1) stationNumHit=3;
109  if (stationNumHit<3 && std::abs(prepDataHit.globalPosition().eta() - roi_eta) < mid_eta_test ) {
110  const float dphi = std::acos(std::cos(prepDataHit.globalPosition().phi()-roi_phi));
111  if (std::abs(dphi-min_dphi_wire)<1e-5) num_min_hits++;
112  if (std::abs(dphi-second_dphi_wire)<1e-5) num_second_hits++;
113  }
114  }
115  }
116  }
117 
118  float dphi_wire=min_dphi_wire;
119  bool useDefault=false;
120  if (num_min_hits<5) {
121  if (num_second_hits>5) dphi_wire=second_dphi_wire;
122  else useDefault=true;
123  }
124 
125  for( const Muon::TgcPrepDataCollection* col : *tgcPrepContainer ) { // loop over collections
126  if( !col ) continue;
127  for( const Muon::TgcPrepData* cit : *col ){ // loop over data in the collection
128  if( !cit ) continue;
129  const Muon::TgcPrepData& prepData = *cit;
130 
131  bool isInRoad = false;
132  int stationNum = m_idHelperSvc->tgcIdHelper().stationRegion(prepData.identify())-1;
133  if (stationNum==-1) stationNum=3;
134  if (m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())) {
135  double dphi = std::abs(prepData.globalPosition().phi() - roi_phi);
136  if( dphi > M_PI*2 ) dphi = dphi - M_PI*2;
137  if( dphi > M_PI ) dphi = M_PI*2 - dphi;
138  // For strips, apply phi cut
139  if ( stationNum < 3 && dphi < mid_phi_test ) { isInRoad = true; }
140  else if( stationNum == 3 && dphi < inn_phi_test ) { isInRoad = true; }
141  }
142  else {
143  // For wires, apply eta cut.
144  const float dphi = std::acos(std::cos(prepData.globalPosition().phi()-roi_phi));
145  if ( stationNum < 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < mid_eta_test ) {
146  if (useDefault) isInRoad = true;//default
147  else if (std::abs(dphi-dphi_wire)<1e-5) isInRoad = true;//for close-by muon
148  }
149  else if( stationNum == 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < inn_eta_test ) { isInRoad = true; }
150  }
151  if( ! isInRoad ) continue;
152 
153  const MuonGM::TgcReadoutElement* tgcReadout = prepData.detectorElement();
154  gasGap = m_idHelperSvc->tgcIdHelper().gasGap(prepData.identify());
155  channel = m_idHelperSvc->tgcIdHelper().channel(prepData.identify());
156 
157  TrigL2MuonSA::TgcHitData lutDigit;
158 
159  lutDigit.eta = prepData.globalPosition().eta();
160  lutDigit.phi = prepData.globalPosition().phi();
161  lutDigit.r = prepData.globalPosition().perp();
162  lutDigit.z = prepData.globalPosition().z();
163  lutDigit.sta = stationNum;
164  lutDigit.isStrip = m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify());
165  if(m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())){
166  lutDigit.width = tgcReadout->stripWidth(gasGap, channel);
167  }
168  else{
169  lutDigit.width = tgcReadout->gangRadialLength(gasGap, channel);
170  }
171  lutDigit.bcTag = 2;
172  lutDigit.inRoad = false;
173 
174 
175  tgcHits.push_back(lutDigit);
176 
177  }
178  }
179 
180  return StatusCode::SUCCESS;
181 }
182 
183 // --------------------------------------------------------------------------------
184 // --------------------------------------------------------------------------------
185 
187  TrigL2MuonSA::TgcHits& tgcHits) const
188 {
189  float roi_eta = p_roi->eta();
190  float roi_phi = p_roi->phi();
191  if (roi_phi < 0) roi_phi += 2.0 * M_PI;
192 
193  //const Muon::TgcPrepDataContainer* tgcPrepContainer = 0;
194  const Muon::TgcPrepDataContainer* tgcPrepContainer;
195  int gasGap;
196  int channel;
197 
198  const bool isLowPt = m_recMuonRoIUtils.isLowPt(p_roi);
199 
200  // Select the eta cut based on ROI Pt.
201  const double mid_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtMiddleForLowPt()
202  : m_options.roadParameters().deltaEtaAtMiddleForHighPt();
203  const double inn_eta_test = (isLowPt) ? m_options.roadParameters().deltaEtaAtInnerForLowPt()
204  : m_options.roadParameters().deltaEtaAtInnerForHighPt();
205  const double mid_phi_test = m_options.roadParameters().deltaPhiAtMiddle();
206  const double inn_phi_test = m_options.roadParameters().deltaPhiAtInner();
207 
208  auto tgcContainerHandle = SG::makeHandle(m_tgcContainerKey);
209  tgcPrepContainer = tgcContainerHandle.cptr();
210  if (!tgcContainerHandle.isValid()) {
211  ATH_MSG_ERROR("Could not retrieve PrepDataContainer key:" << m_tgcContainerKey.key());
212  return StatusCode::FAILURE;
213  } else {
214  ATH_MSG_DEBUG("Retrieved PrepDataContainer: " << tgcPrepContainer->numberOfCollections());
215  }
216 
217  //Find closest wires in Middle
218  float min_dphi_wire=1000.;
219  float second_dphi_wire=1000.;
220  std::vector<float> ov_dphi;
221  ov_dphi.clear();
222  for( const Muon::TgcPrepDataCollection* wi : *tgcPrepContainer ) { // loop over collections
223  if( !wi ) continue;
224  for( const Muon::TgcPrepData* cwi : *wi ){ // loop over data in the collection
225  if( !cwi ) continue;
226  const Muon::TgcPrepData& prepDataWi = *cwi;
227  if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataWi.identify())) {//wire
228  int stationNumWi = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataWi.identify())-1;
229  if (stationNumWi==-1) stationNumWi=3;
230  if (stationNumWi<3 && std::abs(prepDataWi.globalPosition().eta() - roi_eta) < mid_eta_test ) {
231  const float dphi = std::acos(std::cos(prepDataWi.globalPosition().phi()-roi_phi));
232  bool overlap=false;
233  for (unsigned int ov=0;ov<ov_dphi.size();ov++)
234  if (std::abs(dphi-ov_dphi[ov])<1e-5) overlap=true;
235  if (overlap) continue;
236  ov_dphi.push_back(dphi);
237  if (dphi<second_dphi_wire){
238  second_dphi_wire=dphi;
239  }
240  if (dphi<min_dphi_wire) {
241  second_dphi_wire=min_dphi_wire;
242  min_dphi_wire=dphi;
243  }
244  }
245  }
246  }
247  }
248 
249  //Check if there are enough number of hits
250  int num_min_hits=0;
251  int num_second_hits=0;
252  for( const Muon::TgcPrepDataCollection* hit : *tgcPrepContainer ) { // loop over collections
253  if( !hit ) continue;
254  for( const Muon::TgcPrepData* chit : *hit ){ // loop over data in the collection
255  if( !chit ) continue;
256  const Muon::TgcPrepData& prepDataHit = *chit;
257  if (!m_idHelperSvc->tgcIdHelper().isStrip(prepDataHit.identify())) {//strip
258  int stationNumHit = m_idHelperSvc->tgcIdHelper().stationRegion(prepDataHit.identify())-1;
259  if (stationNumHit==-1) stationNumHit=3;
260  if (stationNumHit<3 && std::abs(prepDataHit.globalPosition().eta() - roi_eta) < mid_eta_test ) {
261  const float dphi = std::acos(std::cos(prepDataHit.globalPosition().phi()-roi_phi));
262  if (std::abs(dphi-min_dphi_wire)<1e-5) num_min_hits++;
263  if (std::abs(dphi-second_dphi_wire)<1e-5) num_second_hits++;
264  }
265  }
266  }
267  }
268 
269  float dphi_wire=min_dphi_wire;
270  bool useDefault=false;
271  if (num_min_hits<5) {
272  if (num_second_hits>5) dphi_wire=second_dphi_wire;
273  else useDefault=true;
274  }
275 
276  for( const Muon::TgcPrepDataCollection* col : *tgcPrepContainer ) { // loop over collections
277  if( !col ) continue;
278  for( const Muon::TgcPrepData* cit : *col ){ // loop over data in the collection
279  if( !cit ) continue;
280  const Muon::TgcPrepData& prepData = *cit;
281 
282  bool isInRoad = false;
283  int stationNum = m_idHelperSvc->tgcIdHelper().stationRegion(prepData.identify())-1;
284  if (stationNum==-1) stationNum=3;
285  if (m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())) {
286  double dphi = std::abs(prepData.globalPosition().phi() - roi_phi);
287  if( dphi > M_PI*2 ) dphi = dphi - M_PI*2;
288  if( dphi > M_PI ) dphi = M_PI*2 - dphi;
289  // For strips, apply phi cut
290  if ( stationNum < 3 && dphi < mid_phi_test ) { isInRoad = true; }
291  else if( stationNum == 3 && dphi < inn_phi_test ) { isInRoad = true; }
292  }
293  else {
294  // For wires, apply eta cut.
295  const float dphi = std::acos(std::cos(prepData.globalPosition().phi()-roi_phi));
296  if ( stationNum < 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < mid_eta_test ) {
297  if (useDefault) isInRoad = true;//default
298  else if (std::abs(dphi-dphi_wire)<1e-5) isInRoad = true;//for close-by muon
299  }
300  else if( stationNum == 3 && std::abs(prepData.globalPosition().eta() - roi_eta) < inn_eta_test ) { isInRoad = true; }
301  }
302  if( ! isInRoad ) continue;
303 
304  const MuonGM::TgcReadoutElement* tgcReadout = prepData.detectorElement();
305  gasGap = m_idHelperSvc->tgcIdHelper().gasGap(prepData.identify());
306  channel = m_idHelperSvc->tgcIdHelper().channel(prepData.identify());
307 
308  TrigL2MuonSA::TgcHitData lutDigit;
309 
310  lutDigit.eta = prepData.globalPosition().eta();
311  lutDigit.phi = prepData.globalPosition().phi();
312  lutDigit.r = prepData.globalPosition().perp();
313  lutDigit.z = prepData.globalPosition().z();
314  lutDigit.sta = stationNum;
315  lutDigit.isStrip = m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify());
316  if(m_idHelperSvc->tgcIdHelper().isStrip(prepData.identify())){
317  lutDigit.width = tgcReadout->stripWidth(gasGap, channel);
318  }
319  else{
320  lutDigit.width = tgcReadout->gangRadialLength(gasGap, channel);
321  }
322  lutDigit.bcTag = 2;
323  lutDigit.inRoad = false;
324 
325 
326  tgcHits.push_back(lutDigit);
327 
328  }
329  }
330 
331  return StatusCode::SUCCESS;
332 }
ReadFromCoolCompare.ov
ov
Definition: ReadFromCoolCompare.py:230
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:28
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:120
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
MuonPrepDataContainer.h
LVL1::RecMuonRoI::eta
virtual double eta() const
returns eta coord of ROI
Definition: RecMuonRoI.h:117
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:269
RecMuonRoIUtils.h
TrigL2MuonSA::TgcDataPreparator::initialize
virtual StatusCode initialize() override
Definition: TgcDataPreparator.cxx:23
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
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:146
LVL1::RecMuonRoI
This class defines the reconstructed Muon ROI.
Definition: RecMuonRoI.h:60
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:33
MuonGM::TgcReadoutElement
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/TgcReadoutElement.h:42
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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::TgcDataPreparator::TgcDataPreparator
TgcDataPreparator(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TgcDataPreparator.cxx:13
TrigL2MuonSA::TgcHitData::r
double r
Definition: TgcData.h:31
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
TrigL2MuonSA::TgcDataPreparator::prepareData
StatusCode prepareData(const LVL1::RecMuonRoI *p_roi, TrigL2MuonSA::TgcHits &tgcHits) const
Definition: TgcDataPreparator.cxx:35
LVL1::RecMuonRoI::phi
virtual double phi() const
returns phi coord of ROI
Definition: RecMuonRoI.h:114
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TgcDataPreparator.h
TgcData.h
query_example.col
col
Definition: query_example.py:7
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
TrigL2MuonSA::TgcHitData::z
double z
Definition: TgcData.h:32
TrigL2MuonSA::TgcHitData::bcTag
int bcTag
Definition: TgcData.h:36
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:125
TrigL2MuonSA::TgcHitData::eta
double eta
Definition: TgcData.h:26
AthAlgTool
Definition: AthAlgTool.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.