ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Muon::MuonSegmentOverlapRemovalTool Class Reference

tool to remove overlaps between segments More...

#include <MuonSegmentOverlapRemovalTool.h>

Inheritance diagram for Muon::MuonSegmentOverlapRemovalTool:
Collaboration diagram for Muon::MuonSegmentOverlapRemovalTool:

Public Types

typedef std::vector< MuonSegment * > SegVec
 

Public Member Functions

 MuonSegmentOverlapRemovalTool (const std::string &, const std::string &, const IInterface *)
 constructor More...
 
virtual ~MuonSegmentOverlapRemovalTool ()=default
 destructor More...
 
StatusCode initialize () override
 AlgTool initilize. More...
 
void removeDuplicates (Trk::SegmentCollection &segments) const override
 remove duplicates from a vector of segments. More...
 
std::unique_ptr< MuonSegmentCombinationremoveDuplicates (const MuonSegmentCombination &combi) const override
 remove duplicates from a MuonSegmentCombination. More...
 
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc. More...
 
const ServiceHandle< StoreGateSvc > & evtStore () const
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc. More...
 
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc. More...
 
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm. More...
 
virtual StatusCode sysStart () override
 Handle START transition. More...
 
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles. More...
 
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles. More...
 
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T > &t)
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, SG::VarHandleKey &hndl, const std::string &doc, const SG::VarHandleKeyType &)
 Declare a new Gaudi property. More...
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, SG::VarHandleBase &hndl, const std::string &doc, const SG::VarHandleType &)
 Declare a new Gaudi property. More...
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, SG::VarHandleKeyArray &hndArr, const std::string &doc, const SG::VarHandleKeyArrayType &)
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, T &property, const std::string &doc, const SG::NotHandleType &)
 Declare a new Gaudi property. More...
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, T &property, const std::string &doc="none")
 Declare a new Gaudi property. More...
 
void updateVHKA (Gaudi::Details::PropertyBase &)
 
MsgStream & msg () const
 
MsgStream & msg (const MSG::Level lvl) const
 
bool msgLvl (const MSG::Level lvl) const
 

Static Public Member Functions

static const InterfaceID & interfaceID ()
 access to tool interface More...
 

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution More...
 
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
 
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed. More...
 

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t
 

Private Member Functions

SegVec removeDuplicates (MuonSegmentCombination::SegmentVec &segments) const
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey> More...
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleKeyArrayType &)
 specialization for handling Gaudi::Property<SG::VarHandleKeyArray> More...
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleType &)
 specialization for handling Gaudi::Property<SG::VarHandleBase> More...
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &t, const SG::NotHandleType &)
 specialization for handling everything that's not a Gaudi::Property<SG::VarHandleKey> or a <SG::VarHandleKeyArray> More...
 

Private Attributes

ServiceHandle< Muon::IMuonIdHelperSvcm_idHelperSvc
 
ServiceHandle< Muon::IMuonEDMHelperSvcm_edmHelperSvc
 EDM Helper tool. More...
 
PublicToolHandle< Muon::MuonEDMPrinterToolm_printer
 EDM printer tool. More...
 
Gaudi::Property< bool > m_removePartialOverlaps
 remove partial overlaps between segments More...
 
Gaudi::Property< double > m_overlapFractionCut
 cut on overlap fraction for segments More...
 
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default) More...
 
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default) More...
 
std::vector< SG::VarHandleKeyArray * > m_vhka
 
bool m_varHandleArraysDeclared
 

Detailed Description

tool to remove overlaps between segments

Definition at line 25 of file MuonSegmentOverlapRemovalTool.h.

Member Typedef Documentation

◆ SegVec

Definition at line 45 of file MuonSegmentOverlapRemovalTool.h.

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ MuonSegmentOverlapRemovalTool()

Muon::MuonSegmentOverlapRemovalTool::MuonSegmentOverlapRemovalTool ( const std::string &  ty,
const std::string &  na,
const IInterface *  pa 
)

constructor

Definition at line 14 of file MuonSegmentOverlapRemovalTool.cxx.

14  :
15  AthAlgTool(ty, na, pa) {
16  declareInterface<IMuonSegmentOverlapRemovalTool>(this);
17  }

◆ ~MuonSegmentOverlapRemovalTool()

virtual Muon::MuonSegmentOverlapRemovalTool::~MuonSegmentOverlapRemovalTool ( )
virtualdefault

destructor

Member Function Documentation

◆ declareGaudiProperty() [1/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T > &  hndl,
const SG::VarHandleKeyArrayType  
)
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKeyArray>

Definition at line 170 of file AthCommonDataStore.h.

172  {
173  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
174  hndl.value(),
175  hndl.documentation());
176 
177  }

◆ declareGaudiProperty() [2/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T > &  hndl,
const SG::VarHandleKeyType  
)
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158  {
159  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
160  hndl.value(),
161  hndl.documentation());
162 
163  }

◆ declareGaudiProperty() [3/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T > &  hndl,
const SG::VarHandleType  
)
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleBase>

Definition at line 184 of file AthCommonDataStore.h.

186  {
187  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
188  hndl.value(),
189  hndl.documentation());
190  }

◆ declareGaudiProperty() [4/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T > &  t,
const SG::NotHandleType  
)
inlineprivateinherited

specialization for handling everything that's not a Gaudi::Property<SG::VarHandleKey> or a <SG::VarHandleKeyArray>

Definition at line 199 of file AthCommonDataStore.h.

200  {
201  return PBASE::declareProperty(t);
202  }

◆ declareProperty() [1/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( const std::string &  name,
SG::VarHandleBase hndl,
const std::string &  doc,
const SG::VarHandleType  
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
hndlObject holding the property value.
docDocumentation string for the property.

This is the version for types that derive from SG::VarHandleBase. The property value object is put on the input and output lists as appropriate; then we forward to the base class.

Definition at line 245 of file AthCommonDataStore.h.

249  {
250  this->declare(hndl.vhKey());
251  hndl.vhKey().setOwner(this);
252 
253  return PBASE::declareProperty(name,hndl,doc);
254  }

◆ declareProperty() [2/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( const std::string &  name,
SG::VarHandleKey hndl,
const std::string &  doc,
const SG::VarHandleKeyType  
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
hndlObject holding the property value.
docDocumentation string for the property.

This is the version for types that derive from SG::VarHandleKey. The property value object is put on the input and output lists as appropriate; then we forward to the base class.

Definition at line 221 of file AthCommonDataStore.h.

225  {
226  this->declare(hndl);
227  hndl.setOwner(this);
228 
229  return PBASE::declareProperty(name,hndl,doc);
230  }

◆ declareProperty() [3/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( const std::string &  name,
SG::VarHandleKeyArray hndArr,
const std::string &  doc,
const SG::VarHandleKeyArrayType  
)
inlineinherited

Definition at line 259 of file AthCommonDataStore.h.

263  {
264 
265  // std::ostringstream ost;
266  // ost << Algorithm::name() << " VHKA declareProp: " << name
267  // << " size: " << hndArr.keys().size()
268  // << " mode: " << hndArr.mode()
269  // << " vhka size: " << m_vhka.size()
270  // << "\n";
271  // debug() << ost.str() << endmsg;
272 
273  hndArr.setOwner(this);
274  m_vhka.push_back(&hndArr);
275 
276  Gaudi::Details::PropertyBase* p = PBASE::declareProperty(name, hndArr, doc);
277  if (p != 0) {
278  p->declareUpdateHandler(&AthCommonDataStore<PBASE>::updateVHKA, this);
279  } else {
280  ATH_MSG_ERROR("unable to call declareProperty on VarHandleKeyArray "
281  << name);
282  }
283 
284  return p;
285 
286  }

◆ declareProperty() [4/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( const std::string &  name,
T &  property,
const std::string &  doc,
const SG::NotHandleType  
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
propertyObject holding the property value.
docDocumentation string for the property.

This is the generic version, for types that do not derive from SG::VarHandleKey. It just forwards to the base class version of declareProperty.

Definition at line 333 of file AthCommonDataStore.h.

337  {
338  return PBASE::declareProperty(name, property, doc);
339  }

◆ declareProperty() [5/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( const std::string &  name,
T &  property,
const std::string &  doc = "none" 
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
propertyObject holding the property value.
docDocumentation string for the property.

This dispatches to either the generic declareProperty or the one for VarHandle/Key/KeyArray.

Definition at line 352 of file AthCommonDataStore.h.

355  {
356  typedef typename SG::HandleClassifier<T>::type htype;
357  return declareProperty (name, property, doc, htype());
358  }

◆ declareProperty() [6/6]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T > &  t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145  {
146  typedef typename SG::HandleClassifier<T>::type htype;
148  }

◆ detStore()

const ServiceHandle<StoreGateSvc>& AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

95 { return m_detStore; }

◆ evtStore() [1/2]

ServiceHandle<StoreGateSvc>& AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

85 { return m_evtStore; }

◆ evtStore() [2/2]

const ServiceHandle<StoreGateSvc>& AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( ) const
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 90 of file AthCommonDataStore.h.

90 { return m_evtStore; }

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase &  ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ initialize()

StatusCode Muon::MuonSegmentOverlapRemovalTool::initialize ( )
override

AlgTool initilize.

Definition at line 19 of file MuonSegmentOverlapRemovalTool.cxx.

19  {
21  ATH_CHECK(m_edmHelperSvc.retrieve());
22  ATH_CHECK(m_printer.retrieve());
23  ATH_CHECK(m_idHelperSvc.retrieve());
24  return StatusCode::SUCCESS;
25  }

◆ inputHandles()

virtual std::vector<Gaudi::DataHandle*> AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ interfaceID()

static const InterfaceID& Muon::IMuonSegmentOverlapRemovalTool::interfaceID ( )
inlinestaticinherited

access to tool interface

Definition at line 25 of file IMuonSegmentOverlapRemovalTool.h.

25  {
26  static const InterfaceID IID_IMuonSegmentOverlapRemovalTool("Muon::IMuonSegmentOverlapRemovalTool", 1, 0);
27  return IID_IMuonSegmentOverlapRemovalTool;
28  }

◆ msg() [1/2]

MsgStream& AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24  {
25  return this->msgStream();
26  }

◆ msg() [2/2]

MsgStream& AthCommonMsg< AlgTool >::msg ( const MSG::Level  lvl) const
inlineinherited

Definition at line 27 of file AthCommonMsg.h.

27  {
28  return this->msgStream(lvl);
29  }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30  {
31  return this->msgLevel(lvl);
32  }

◆ outputHandles()

virtual std::vector<Gaudi::DataHandle*> AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ removeDuplicates() [1/3]

std::unique_ptr< MuonSegmentCombination > Muon::MuonSegmentOverlapRemovalTool::removeDuplicates ( const MuonSegmentCombination combi) const
overridevirtual

remove duplicates from a MuonSegmentCombination.

The callers should take ownership of the new SegmentCombination. If the combination is unchanged the routine will return a nullptr

Implements Muon::IMuonSegmentOverlapRemovalTool.

Definition at line 173 of file MuonSegmentOverlapRemovalTool.cxx.

173  {
174  // store pointers to segments that should be kept
175  std::set<MuonSegment*> segmentsToBeKept;
176  unsigned int nsegments = 0; // total number of segments
177 
178  unsigned int nstations = combi.numberOfStations();
179 
180  ATH_MSG_DEBUG(" removing duplicate from MuonSegmentCombination with " << nstations << " stations");
181 
182  // loop over segments, add them to the chamber layers
183  // loop over chambers in combi and extract segments
184  for (unsigned int i = 0; i < nstations; ++i) {
185  // loop over segments in station
186  MuonSegmentCombination::SegmentVec* stationSegs = combi.stationSegments(i);
187 
188  // check if not empty
189  if (!stationSegs || stationSegs->empty()) continue;
190 
191  nsegments += stationSegs->size();
192 
193  // clean segments
194  SegVec cleanedSegments = removeDuplicates(*stationSegs);
195  segmentsToBeKept.insert(cleanedSegments.begin(), cleanedSegments.end());
196  }
197 
198  // check whether all segments were kept
199  if (nsegments == segmentsToBeKept.size()) {
200  ATH_MSG_DEBUG(" no segments removed ");
201  return nullptr;
202  }
203 
204  std::unique_ptr<MuonSegmentCombination> newCombi = std::make_unique<MuonSegmentCombination>();
205 
206  // create a new combination removing segments that overlap
207  for (unsigned int i = 0; i < nstations; ++i) {
208  // loop over segments in station
209  MuonSegmentCombination::SegmentVec* stationSegs = combi.stationSegments(i);
210 
211  // check if not empty
212  if (!stationSegs || stationSegs->empty()) continue;
213 
214  std::unique_ptr<std::vector<std::unique_ptr<MuonSegment>>> segVec =
215  std::make_unique<std::vector<std::unique_ptr<MuonSegment>>>();
216  segVec->reserve(stationSegs->size());
217 
218  // loop over segments and add them if they are in the keep set
219  for (const std::unique_ptr<MuonSegment>& seg : *stationSegs) {
220  if (!segmentsToBeKept.count(seg.get())) {
221  continue;
222  } else {
223  segVec->emplace_back(seg->clone());
224  }
225  }
226  // if not empty add segments
227  if (!segVec->empty()) newCombi->addSegments(std::move(segVec));
228  }
229 
230  ATH_MSG_DEBUG(" removed " << nsegments - segmentsToBeKept.size() << " duplicates, new size " << segmentsToBeKept.size());
231 
232  return newCombi;
233  }

◆ removeDuplicates() [2/3]

MuonSegmentOverlapRemovalTool::SegVec Muon::MuonSegmentOverlapRemovalTool::removeDuplicates ( MuonSegmentCombination::SegmentVec segments) const
private

Definition at line 237 of file MuonSegmentOverlapRemovalTool.cxx.

238  {
239  ATH_MSG_DEBUG(" working on segment vector of size " << segments.size());
240 
241  CompareMuonSegmentKeys compareSegmentKeys{};
242 
243  // create a vector with pairs of MuonSegmentKey and a pointer to the corresponding segment to resolve ambiguities
244  std::vector<std::pair<MuonSegmentKey, MuonSegment*>> goodSegments;
245  goodSegments.reserve(segments.size());
246 
247  // loop over new segments, copy them into collection
248  for (const std::unique_ptr<MuonSegment>& seg : segments) {
249  // create segment key object
250  MuonSegmentKey sk(*seg);
251  Identifier chId = m_edmHelperSvc->chamberId(*seg);
252  bool isCsc = m_idHelperSvc->isCsc(chId);
253 
254  // should this segment be inserted?
255  bool insertAsGood(true);
256 
257  // loop over already accepted segments and compare the current segment with the good ones
258  for (std::pair<MuonSegmentKey, MuonSegment*>& good_seg : goodSegments) {
259  CompareMuonSegmentKeys::OverlapResult overlapResult = compareSegmentKeys(good_seg.first, sk);
260  if (overlapResult == CompareMuonSegmentKeys::Identical) {
261  // for now keep the one with the best chi2
262  const Trk::FitQuality* fq1 = good_seg.second->fitQuality();
263  const Trk::FitQuality* fq2 = seg->fitQuality();
264  double chi2good = fq1 ? fq1->chiSquared() : 1e10;
265  double chi2current = fq2 ? fq2->chiSquared() : 1e10;
266  // we should not insert this segment
267  if (chi2good > chi2current) {
268  ATH_MSG_VERBOSE(" replacing (chi2) " << m_printer->print(*good_seg.second) << std::endl
269  << " with " << m_printer->print(*seg));
270 
271  // good segment of worse quality, replace it
272  good_seg.first = sk;
273  good_seg.second = seg.get();
274  } else {
275  ATH_MSG_VERBOSE(" discarding (chi2) " << m_printer->print(*seg));
276  }
277  insertAsGood = false;
278  break;
279  } else if (overlapResult == CompareMuonSegmentKeys::SuperSet) {
280  // good segment of better quality, keep it and discard current segment
281  ATH_MSG_VERBOSE(" discarding (subset) " << m_printer->print(*seg));
282  insertAsGood = false;
283  break;
284  } else if (overlapResult == CompareMuonSegmentKeys::SubSet) {
285  // good segment of worse quality, replace it
286  ATH_MSG_VERBOSE(" replacing (superset) " << m_printer->print(*good_seg.second) << std::endl
287  << " with " << m_printer->print(*seg));
288  good_seg.first = sk;
289  good_seg.second = seg.get();
290  insertAsGood = false;
291  break;
292  } else if (overlapResult == CompareMuonSegmentKeys::PartialOverlap && m_removePartialOverlaps) {
293  // keep CSC segments with partial overlap
294  if (isCsc) continue;
295 
296  // partial overlap, for now keep the one most hits
297  if (compareSegmentKeys.segment1Size < compareSegmentKeys.segment2Size) {
298  ATH_MSG_VERBOSE(" replacing (mdt hits) " << m_printer->print(*good_seg.second) << std::endl
299  << " with " << m_printer->print(*seg));
300 
301  // good segment of worse quality, replace it
302  good_seg.first = sk;
303  good_seg.second = seg.get();
304  } else if (compareSegmentKeys.segment1Size == compareSegmentKeys.segment2Size) {
305  // same size
306 
307  // if the original entry has more trigger hits discard current segment
308  if (compareSegmentKeys.segment1SizeTrigger > compareSegmentKeys.segment2SizeTrigger) {
309  ATH_MSG_VERBOSE(" discarding (trigger hits) " << m_printer->print(*seg));
310  insertAsGood = false;
311  break;
312  } else if (compareSegmentKeys.segment1SizeTrigger < compareSegmentKeys.segment2SizeTrigger) {
313  // good segment of worse quality, replace it
314  ATH_MSG_VERBOSE(" replacing (trigger hits) " << m_printer->print(*good_seg.second) << std::endl
315  << " with " << m_printer->print(*seg));
316  good_seg.first = sk;
317  good_seg.second = seg.get();
318  insertAsGood = false;
319  break;
320  } else if (compareSegmentKeys.segment1SizeTrigger == compareSegmentKeys.segment2SizeTrigger) {
321  // for now look at the overlap fraction
322  }
323  // calculate the overlap fraction
324  double overlapFraction = (double)compareSegmentKeys.intersectionSize / (double)compareSegmentKeys.segment1Size;
325  if (overlapFraction > m_overlapFractionCut) {
326  ATH_MSG_VERBOSE(" discarding (overlap fraction) " << m_printer->print(*seg));
327  insertAsGood = false;
328  break;
329  }
330 
331  continue;
332  } else {
333  ATH_MSG_VERBOSE(" discarding " << m_printer->print(*seg));
334  }
335  insertAsGood = false;
336  break;
337  } else if (overlapResult == CompareMuonSegmentKeys::NoOverlap) {
338  // no overlap, move on to next segment
339  continue;
340  } else if (overlapResult == CompareMuonSegmentKeys::Unknown) {
341  ATH_MSG_WARNING(" Got invalid return argument comparing segments: " << compareSegmentKeys.print(overlapResult));
342  continue;
343  }
344  }
345 
346  // add segment if needed
347  if (insertAsGood) {
348  ATH_MSG_VERBOSE(" no overlap " << m_printer->print(*seg));
349  goodSegments.emplace_back(sk, seg.get());
350  }
351  }
352 
353  SegVec cleanedSegments;
354  for (const std::pair<MuonSegmentKey, MuonSegment*>& good_seg : goodSegments) { cleanedSegments.push_back(good_seg.second); }
355  ATH_MSG_DEBUG(" Segments after removal " << cleanedSegments.size() << " total number of removed segments "
356  << segments.size() - cleanedSegments.size());
357 
358  return cleanedSegments;
359  }

◆ removeDuplicates() [3/3]

void Muon::MuonSegmentOverlapRemovalTool::removeDuplicates ( Trk::SegmentCollection segments) const
overridevirtual

remove duplicates from a vector of segments.

The caller should take ownership of the segments

Implements Muon::IMuonSegmentOverlapRemovalTool.

Definition at line 27 of file MuonSegmentOverlapRemovalTool.cxx.

27  {
28  ATH_MSG_DEBUG(" working on segment vector of size " << segments.size());
29 
30  CompareMuonSegmentKeys compareSegmentKeys{};
31 
32  // create a vector with pairs of MuonSegmentKey and a pointer to the corresponding segment to resolve ambiguities
33  std::vector<std::pair<MuonSegmentKey, MuonSegment*>> goodSegments;
34  goodSegments.reserve(segments.size());
35  std::vector<MuonSegment*> segmentsToErase;
36 
37  // loop over new segments, copy them into collection
38  for (Trk::Segment* tseg : segments) {
39  // create segment key object
40  MuonSegment* seg = dynamic_cast<MuonSegment*>(tseg);
41  if (!seg) {
42  ATH_MSG_WARNING("segment is not MuonSegment");
43  continue;
44  }
45  MuonSegmentKey sk{*seg};
46  Identifier chId = m_edmHelperSvc->chamberId(*seg);
47  bool isCsc = m_idHelperSvc->isCsc(chId);
48 
49  // should this segment be inserted?
50  bool insertAsGood = true;
51 
52  // loop over already accepted segments and compare the current segment with the good ones
53  for (std::pair<MuonSegmentKey, MuonSegment*>& good_seg : goodSegments) {
54  CompareMuonSegmentKeys::OverlapResult overlapResult = compareSegmentKeys(good_seg.first, sk);
55  if (overlapResult == CompareMuonSegmentKeys::Identical) {
56  // for now keep the one with the best chi2
57  const Trk::FitQuality* fq1 = good_seg.second->fitQuality();
58  const Trk::FitQuality* fq2 = seg->fitQuality();
59  double chi2good = fq1 ? fq1->chiSquared() : 1e10;
60  double chi2current = fq2 ? fq2->chiSquared() : 1e10;
61  // we should not insert this segment
62  if (chi2good > chi2current) {
63  ATH_MSG_VERBOSE(" replacing (chi2) " << m_printer->print(*good_seg.second) << std::endl
64  << " with " << m_printer->print(*seg));
65 
66  // good segment of worse quality, replace it
67  segmentsToErase.push_back(good_seg.second);
68  good_seg.first = sk;
69  good_seg.second = seg;
70 
71  } else {
72  ATH_MSG_VERBOSE(" discarding (chi2) " << m_printer->print(*seg));
73  segmentsToErase.push_back(seg);
74  }
75  insertAsGood = false;
76  break;
77  } else if (overlapResult == CompareMuonSegmentKeys::SuperSet) {
78  // good segment of better quality, keep it and discard current segment
79  ATH_MSG_VERBOSE(" discarding (subset) " << m_printer->print(*seg));
80  segmentsToErase.push_back(seg);
81  insertAsGood = false;
82  break;
83  } else if (overlapResult == CompareMuonSegmentKeys::SubSet) {
84  // good segment of worse quality, replace it
85  ATH_MSG_VERBOSE(" replacing (superset) " << m_printer->print(*good_seg.second) << std::endl
86  << " with " << m_printer->print(*seg));
87  segmentsToErase.push_back(good_seg.second);
88  good_seg.first = sk;
89  good_seg.second = seg;
90  insertAsGood = false;
91  break;
92  } else if (overlapResult == CompareMuonSegmentKeys::PartialOverlap && m_removePartialOverlaps) {
93  // keep CSC segments with partial overlap
94  if (isCsc) continue;
95 
96  // partial overlap, for now keep the one most hits
97  if (compareSegmentKeys.segment1Size < compareSegmentKeys.segment2Size) {
98  ATH_MSG_VERBOSE(" replacing (mdt hits) " << m_printer->print(*good_seg.second) << std::endl
99  << " with " << m_printer->print(*seg));
100 
101  // good segment of worse quality, replace it
102  segmentsToErase.push_back(good_seg.second);
103  good_seg.first = sk;
104  good_seg.second = seg;
105  insertAsGood = false;
106  break;
107  } else if (compareSegmentKeys.segment1Size == compareSegmentKeys.segment2Size) {
108  // same size
109 
110  // if the original entry has more trigger hits discard current segment
111  if (compareSegmentKeys.segment1SizeTrigger > compareSegmentKeys.segment2SizeTrigger) {
112  ATH_MSG_VERBOSE(" discarding (trigger hits) " << m_printer->print(*seg));
113  segmentsToErase.push_back(seg);
114  insertAsGood = false;
115  break;
116  } else if (compareSegmentKeys.segment1SizeTrigger < compareSegmentKeys.segment2SizeTrigger) {
117  // good segment of worse quality, replace it
118  ATH_MSG_VERBOSE(" replacing (trigger hits) " << m_printer->print(*good_seg.second) << std::endl
119  << " with " << m_printer->print(*seg));
120  segmentsToErase.push_back(good_seg.second);
121  good_seg.first = sk;
122  good_seg.second = seg;
123  insertAsGood = false;
124  break;
125  } else if (compareSegmentKeys.segment1SizeTrigger == compareSegmentKeys.segment2SizeTrigger) {
126  // for now look at the overlap fraction
127  }
128  // calculate the overlap fraction
129  double overlapFraction = (double)compareSegmentKeys.intersectionSize / (double)compareSegmentKeys.segment1Size;
130  if (overlapFraction > m_overlapFractionCut) {
131  ATH_MSG_VERBOSE(" discarding (overlap fraction) " << m_printer->print(*seg));
132  segmentsToErase.push_back(seg);
133  insertAsGood = false;
134  break;
135  }
136 
137  continue;
138  } else {
139  ATH_MSG_VERBOSE(" discarding " << m_printer->print(*seg));
140  segmentsToErase.push_back(seg);
141  }
142  insertAsGood = false;
143  break;
144  } else if (overlapResult == CompareMuonSegmentKeys::NoOverlap) {
145  // no overlap, move on to next segment
146  continue;
147  } else if (overlapResult == CompareMuonSegmentKeys::Unknown) {
148  ATH_MSG_WARNING(" Got invalid return argument comparing segments: " << compareSegmentKeys.print(overlapResult));
149  continue;
150  }
151  }
152 
153  // add segment if needed
154  if (insertAsGood) {
155  ATH_MSG_VERBOSE(" no overlap " << m_printer->print(*seg));
156  goodSegments.emplace_back(std::move(sk), seg);
157  }
158  }
159 
160  // erase rejected segments
161  for (MuonSegment* to_erase : segmentsToErase) {
162  for (Trk::SegmentCollection::iterator sit = segments.begin(); sit != segments.end(); ++sit) {
163  // remove bad segments from collection, then delete them
164  Trk::Segment* tseg = *sit;
165  if (to_erase == dynamic_cast<MuonSegment*>(tseg)) {
166  segments.erase(sit);
167  break;
168  }
169  }
170  }
171  }

◆ renounce()

std::enable_if_t<std::is_void_v<std::result_of_t<decltype(&T::renounce)(T)> > && !std::is_base_of_v<SG::VarHandleKeyArray, T> && std::is_base_of_v<Gaudi::DataHandle, T>, void> AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T &  h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381  {
382  h.renounce();
383  PBASE::renounce (h);
384  }

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364  {
365  handlesArray.renounce();
366  }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in DerivationFramework::CfAthAlgTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and asg::AsgMetadataTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase &  )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308  {
309  // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310  // << " size: " << m_vhka.size() << endmsg;
311  for (auto &a : m_vhka) {
312  std::vector<SG::VarHandleKey*> keys = a->keys();
313  for (auto k : keys) {
314  k->setOwner(this);
315  }
316  }
317  }

Member Data Documentation

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_edmHelperSvc

ServiceHandle<Muon::IMuonEDMHelperSvc> Muon::MuonSegmentOverlapRemovalTool::m_edmHelperSvc
private
Initial value:
{
this,
"edmHelper",
"Muon::MuonEDMHelperSvc/MuonEDMHelperSvc",
"Handle to the service providing the IMuonEDMHelperSvc interface",
}

EDM Helper tool.

Definition at line 57 of file MuonSegmentOverlapRemovalTool.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_idHelperSvc

ServiceHandle<Muon::IMuonIdHelperSvc> Muon::MuonSegmentOverlapRemovalTool::m_idHelperSvc
private
Initial value:
{
this,
"MuonIdHelperSvc",
"Muon::MuonIdHelperSvc/MuonIdHelperSvc",
}

Definition at line 52 of file MuonSegmentOverlapRemovalTool.h.

◆ m_overlapFractionCut

Gaudi::Property<double> Muon::MuonSegmentOverlapRemovalTool::m_overlapFractionCut
private
Initial value:
{
this, "OverlapFractionCut", 0.8,
"Cut overlap fraction, if fraction is smaller than cut both segments are kept"}

cut on overlap fraction for segments

Definition at line 73 of file MuonSegmentOverlapRemovalTool.h.

◆ m_printer

PublicToolHandle<Muon::MuonEDMPrinterTool> Muon::MuonSegmentOverlapRemovalTool::m_printer
private
Initial value:
{
this,
"Printer",
"Muon::MuonEDMPrinterTool/MuonEDMPrinterTool",
}

EDM printer tool.

Definition at line 64 of file MuonSegmentOverlapRemovalTool.h.

◆ m_removePartialOverlaps

Gaudi::Property<bool> Muon::MuonSegmentOverlapRemovalTool::m_removePartialOverlaps
private
Initial value:
{
this, "RemovePartialOverlaps", true,
"removal partial overlaps between segments"}

remove partial overlaps between segments

Definition at line 70 of file MuonSegmentOverlapRemovalTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files:
Muon::CompareMuonSegmentKeys::PartialOverlap
@ PartialOverlap
Definition: CompareMuonSegmentKeys.h:20
Muon::CompareMuonSegmentKeys::SubSet
@ SubSet
Definition: CompareMuonSegmentKeys.h:18
AthCommonDataStore::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
initialize
void initialize()
Definition: run_EoverP.cxx:894
AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
Definition: AthCommonDataStore.h:390
AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
std::vector< SG::VarHandleKeyArray * > m_vhka
Definition: AthCommonDataStore.h:398
Muon::MuonSegmentOverlapRemovalTool::SegVec
std::vector< MuonSegment * > SegVec
Definition: MuonSegmentOverlapRemovalTool.h:45
Muon::MuonSegmentOverlapRemovalTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonSegmentOverlapRemovalTool.h:52
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::MuonSegment
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonSegment.h:13
Muon::MuonSegmentOverlapRemovalTool::removeDuplicates
void removeDuplicates(Trk::SegmentCollection &segments) const override
remove duplicates from a vector of segments.
Definition: MuonSegmentOverlapRemovalTool.cxx:27
SG::VarHandleKeyArray::setOwner
virtual void setOwner(IDataHandleHolder *o)=0
IDTPMcnv.htype
htype
Definition: IDTPMcnv.py:29
Muon::CompareMuonSegmentKeys::OverlapResult
OverlapResult
enum for the overlap result
Definition: CompareMuonSegmentKeys.h:16
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
AthCommonDataStore
Definition: AthCommonDataStore.h:52
Muon::CompareMuonSegmentKeys::Identical
@ Identical
Definition: CompareMuonSegmentKeys.h:17
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Muon::MuonSegmentOverlapRemovalTool::m_removePartialOverlaps
Gaudi::Property< bool > m_removePartialOverlaps
remove partial overlaps between segments
Definition: MuonSegmentOverlapRemovalTool.h:70
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
lumiFormat.i
int i
Definition: lumiFormat.py:85
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::Segment
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:56
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::FitQuality
Class to represent and store fit qualities from track reconstruction in terms of and number of degre...
Definition: FitQuality.h:97
AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)
Definition: AthCommonDataStore.h:393
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
AthAlgTool::AthAlgTool
AthAlgTool()
Default constructor:
Muon::MuonSegmentOverlapRemovalTool::m_printer
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
EDM printer tool.
Definition: MuonSegmentOverlapRemovalTool.h:64
SG::VarHandleKeyArray::renounce
virtual void renounce()=0
SG::HandleClassifier::type
std::conditional< std::is_base_of< SG::VarHandleKeyArray, T >::value, VarHandleKeyArrayType, type2 >::type type
Definition: HandleClassifier.h:54
Muon::CompareMuonSegmentKeys::Unknown
@ Unknown
Definition: CompareMuonSegmentKeys.h:22
merge_scale_histograms.doc
string doc
Definition: merge_scale_histograms.py:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Muon::MuonSegmentOverlapRemovalTool::m_overlapFractionCut
Gaudi::Property< double > m_overlapFractionCut
cut on overlap fraction for segments
Definition: MuonSegmentOverlapRemovalTool.h:73
a
TList * a
Definition: liststreamerinfos.cxx:10
Muon::CompareMuonSegmentKeys::NoOverlap
@ NoOverlap
Definition: CompareMuonSegmentKeys.h:21
h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Muon::MuonSegmentCombination::SegmentVec
std::vector< std::unique_ptr< MuonSegment > > SegmentVec
Definition: MuonSegmentCombination.h:32
SG::VarHandleBase::vhKey
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
Definition: StoreGate/src/VarHandleBase.cxx:623
Trk::FitQuality::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
Muon::MuonSegmentOverlapRemovalTool::m_edmHelperSvc
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
EDM Helper tool.
Definition: MuonSegmentOverlapRemovalTool.h:57
Muon::CompareMuonSegmentKeys::SuperSet
@ SuperSet
Definition: CompareMuonSegmentKeys.h:19
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
AthCommonDataStore::declareGaudiProperty
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>
Definition: AthCommonDataStore.h:156
fitman.k
k
Definition: fitman.py:528
Identifier
Definition: IdentifierFieldParser.cxx:14