ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonEFInfo.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*****************************************************************************
6Name : TrigMuonEFInfo.cxx
7Package : offline/Trigger/TrigEvent/TrigMuonEvent
8Author : Sergio Grancagnolo
9Created : April 2008
10Note : Trigger container AOD for EF Muon (TrigMuonEFInfo)
11
12DESCRIPTION:
13
14Apr.2008: An AOD containing RoI index and track parameters for each
15 muon trigger step.
16 *****************************************************************************/
17
18// STL include(s):
19#include <sstream>
20
21// Gaudi/Athena include(s):
22#include "GaudiKernel/MsgStream.h"
23
24// Local include(s):
29
30TrigMuonEFInfo::TrigMuonEFInfo( unsigned short int theRoI,
31 std::unique_ptr<TrigMuonEFInfoTrackContainer> tracks)
32 : m_roi (theRoI),
33 m_nSegments (0),
34 m_nMdtHits (0),
35 m_nRpcHits (0),
36 m_nTgcHits (0),
37 m_nCscHits (0),
40 m_trackContainer (tracks.release())
41{
42 // these objects have to be created to guard
43 // backward compatibilty for the TPCnv package.
44 // they are not stored.
48}
49
50
51TrigMuonEFInfo::TrigMuonEFInfo( unsigned short int theRoI,
52 std::unique_ptr<TrigMuonEFInfoTrackContainer> tracks,
53 std::unique_ptr<TrigMuonEFTrack> spectrometerTrack,
54 std::unique_ptr<TrigMuonEFTrack> extrapolatedTrack,
55 std::unique_ptr<TrigMuonEFCbTrack> combinedTrack)
56 : m_roi (theRoI),
57 m_nSegments (0),
58 m_nMdtHits (0),
59 m_nRpcHits (0),
60 m_nTgcHits (0),
61 m_nCscHits (0),
64 m_trackContainer (tracks.release()),
65 m_spectrometerTrack (spectrometerTrack.release()),
66 m_extrapolatedTrack (extrapolatedTrack.release()),
67 m_combinedTrack (combinedTrack.release())
68{
69}
70
71
72TrigMuonEFInfo::TrigMuonEFInfo( unsigned short int theRoI )
73{
74
75 m_roi = theRoI;
76 m_nSegments = 0;
77 m_nMdtHits = 0;
78 m_nRpcHits = 0;
79 m_nCscHits = 0;
80 m_nTgcHits = 0;
83
85
86 // these objects have to be created to guard
87 // backward compatibilty for the TPCnv package.
88 // they are not stored.
92}
93
94
96{
98 m_nSegments = 0;
99 m_nMdtHits = 0;
100 m_nRpcHits = 0;
101 m_nCscHits = 0;
102 m_nTgcHits = 0;
105
107
108 // these objects have to be created to guard
109 // backward compatibilty for the TPCnv package.
110 // they are not stored.
114}
115
117 m_roi( rhs.m_roi ),
119 m_nMdtHits( rhs.m_nMdtHits ),
120 m_nRpcHits( rhs.m_nRpcHits ),
121 m_nTgcHits( rhs.m_nTgcHits ),
122 m_nCscHits( rhs.m_nCscHits ),
125 {
126
127 // deep copy of m_trackContainer
129 for (const TrigMuonEFInfoTrack* t : *rhs.m_trackContainer)
130 { // loop over container content
131 m_trackContainer->push_back(std::make_unique<TrigMuonEFInfoTrack>(*t));
132 }
133
134 // check for legacy tracks
137 m_combinedTrack = 0;
138 if (rhs.m_spectrometerTrack)
140 if (rhs.m_extrapolatedTrack)
142 if (rhs.m_combinedTrack)
143 m_combinedTrack = new TrigMuonEFCbTrack( *rhs.m_combinedTrack ); // legacy
144
145}
146
148{
149
150 if ( this != &rhs ) {
151 m_roi = rhs.m_roi;
159
160 // clean up
161 delete m_trackContainer;
162
163 // deep copy of m_trackContainer
165 for (const TrigMuonEFInfoTrack* t : *rhs.m_trackContainer)
166 {
167 m_trackContainer->push_back(std::make_unique<TrigMuonEFInfoTrack>(*t));
168 }
169
170 // check for legacy tracks
171 if (rhs.m_spectrometerTrack) {
172 delete m_spectrometerTrack;
174 }
175 if (rhs.m_extrapolatedTrack) {
176 delete m_extrapolatedTrack;
178 }
179 if (rhs.m_combinedTrack) {
180 delete m_combinedTrack;
181 m_combinedTrack = new TrigMuonEFCbTrack( *rhs.m_combinedTrack ); // legacy
182 }
183
184 }
185 return *this;
186}
187
189{
190
191 if ( this != &rhs ) {
192 m_roi = rhs.m_roi;
193 m_nSegments = rhs.m_nSegments;
194 m_nMdtHits = rhs.m_nMdtHits;
195 m_nRpcHits = rhs.m_nRpcHits;
196 m_nTgcHits = rhs.m_nTgcHits;
197 m_nCscHits = rhs.m_nCscHits;
198 m_etaPreviousLevel = rhs.m_etaPreviousLevel;
199 m_phiPreviousLevel = rhs.m_phiPreviousLevel;
200
201 std::swap (m_trackContainer, rhs.m_trackContainer);
202 std::swap (m_spectrometerTrack, rhs.m_spectrometerTrack);
203 std::swap (m_extrapolatedTrack, rhs.m_extrapolatedTrack);
204 std::swap (m_combinedTrack, rhs.m_combinedTrack);
205
206 }
207 return *this;
208}
209
217
218void TrigMuonEFInfo::setRoINum( unsigned short int theRoINum )
219{
220 m_roi = theRoINum;
221 return;
222}
223
224void TrigMuonEFInfo::setNSegments( unsigned short int theNSegments )
225{
226 m_nSegments = theNSegments;
227 return;
228}
229
230
231void TrigMuonEFInfo::setNMdtHits( unsigned short int theNMdtHits )
232{
233 m_nMdtHits = theNMdtHits;
234 return;
235}
236
237void TrigMuonEFInfo::setNRpcHits( unsigned short int theNRpcHits )
238{
239 m_nRpcHits = theNRpcHits;
240 return;
241}
242
243void TrigMuonEFInfo::setNTgcHits( unsigned short int theNTgcHits )
244{
245 m_nTgcHits = theNTgcHits;
246 return;
247}
248
249void TrigMuonEFInfo::setNCscHits( unsigned short int theNCscHits )
250{
251 m_nCscHits = theNCscHits;
252 return;
253}
254
255void TrigMuonEFInfo::setEtaPreviousLevel( double theEtaPreviousLevel )
256{
257 m_etaPreviousLevel = theEtaPreviousLevel;
258 return;
259}
260
261void TrigMuonEFInfo::setPhiPreviousLevel( double thePhiPreviousLevel )
262{
263 m_phiPreviousLevel = thePhiPreviousLevel;
264 return;
265}
266
268
269 m_trackContainer->push_back(theTrack);
270
271 return;
272}
273
275{
276 if (!hasTrack()) {
278 }
279 TrigMuonEFInfoTrack *track = (*(m_trackContainer->begin()));
280 track->setSpectrometerTrack(theTrack);
281 return;
282}
283
285{
286 if (!hasTrack() && !hasLegacyTrack()) {
288 return (*(m_trackContainer->begin()))->SpectrometerTrack();
289 }
290 else if (hasLegacyTrack()) {
291 return(m_spectrometerTrack);
292 }
293 return (*(m_trackContainer->begin()))->SpectrometerTrack();
294}
295
297{
298 if (!hasTrack()) {
300 }
301 TrigMuonEFInfoTrack *track = (*(m_trackContainer->begin()));
302 track->setExtrapolatedTrack(theTrack);
303 return;
304}
305
307{
308 if (!hasTrack() && !hasLegacyTrack()) {
310 return (*(m_trackContainer->begin()))->ExtrapolatedTrack();
311 }
312 else if ( hasLegacyTrack()) {
313 return(m_extrapolatedTrack);
314 }
315 return (*(m_trackContainer->begin()))->ExtrapolatedTrack();
316
317}
318
320{
321 if (!hasTrack()) {
323 }
324 TrigMuonEFInfoTrack *track = (*(m_trackContainer->begin()));
325 track->setCombinedTrack(theTrack);
326 return;
327}
328
330{
331 if (!hasTrack() && !hasLegacyTrack()) {
333 return (*(m_trackContainer->begin()))->CombinedTrack();
334 }
335 else if ( hasLegacyTrack()) {
336 return(m_combinedTrack);
337 }
338 return (*(m_trackContainer->begin()))->CombinedTrack();
339}
340
342 // object, legacy tracks?
343 if (!m_trackContainer) {
344 return false;
345 }
346 // trackContainer empty?
347 else if (m_trackContainer->size()>0) {
348 return true;
349 }
350 else {
351 return false;
352 }
353}
354
356
357 if ( m_spectrometerTrack==0
359 || m_combinedTrack==0) {
360 return false;
361 }
362 else if (
363 m_spectrometerTrack->charge()!=m_spectrometerTrack->CHARGE_NA ||
364 m_extrapolatedTrack->charge()!=m_extrapolatedTrack->CHARGE_NA ||
365 m_combinedTrack->charge()!=m_combinedTrack->CHARGE_NA ||
366 m_spectrometerTrack->m()!=0. || // legacy, charge wasn't stored until p2
367 m_extrapolatedTrack->m()!=0. || // of TrigMuonEFTrackCnv
368 m_combinedTrack->m()!=0.
369
370 ) {
371 return true;
372 }
373 else {
374 return false;
375 }
376}
377
378// legacy method, should not be used anymore
380 return (hasLegacyTrack()||hasTrack());
381}
382
383// legacy method, should not be used anymore
385 return (hasLegacyTrack()||hasTrack());
386}
387
388// legacy method, should not be used anymore
390 return (hasLegacyTrack()||hasTrack());
391}
392
394// helper functions
395
397// helper operators
398
399std::string str ( const TrigMuonEFInfo& d ) {
400 std::stringstream ss;
401 ss << "RoI index: " << d.RoINum()
402 << "; NSegments: " << d.NSegments()
403 << "; NMdtHits: " << d.NMdtHits()
404 << "; NRpcHits: " << d.NRpcHits()
405 << "; NTgcHits: " << d.NTgcHits()
406 << "; NCscHits: " << d.NCscHits()
407 << "; hasTrack: " << d.hasTrack() << std::endl;
408
409 if (d.hasTrack()) {
410
411 // find match in containerB
412 for (const TrigMuonEFInfoTrack* dd : *d.TrackContainer()) {
413 if (dd) {
414
415 ss << "; muon type: " << dd->MuonType();
416
417 if (dd->hasSpectrometerTrack())
418 ss << "; spectrometer track: " << dd->SpectrometerTrack()
419 << " : " << *(dd->SpectrometerTrack());
420
421 if (dd->hasExtrapolatedTrack())
422 ss << "; extrapolated track: " << dd->ExtrapolatedTrack()
423 << " : " << *(dd->ExtrapolatedTrack());
424
425 if (dd->hasCombinedTrack())
426 ss << "; combined track: " << dd->CombinedTrack()
427 << " : " << *(dd->CombinedTrack());
428 }
429 }
430 }
431 return ss.str();
432}
433
434MsgStream& operator<< ( MsgStream& m, const TrigMuonEFInfo& d ) {
435
436 return ( m << str( d ) );
437}
438
439bool operator== ( const TrigMuonEFInfo& a, const TrigMuonEFInfo& b ) {
440
441 if ( a.RoINum() != b.RoINum() )
442 return false;
443 if ( a.hasTrack() != b.hasTrack() )
444 return false;
445 if (a.hasTrack() && b.hasTrack() ) {
446 // simple check for the number of entries in container:
447 if ( a.TrackContainer()->size() != b.TrackContainer()->size() )
448 {
449 return false;
450 }
451 // sort container?
452 // unfortunately sort() of DataVector just sorts by pointer value,
453 // so really useless here....
454 // policy: make a copy of container B (tmpContB) and loop over container A
455 // for every match rm element from tmpContB.
456 // at the end check whether tmpContB is empty -> condition for equality
457
458 // make a view copy of container B to rm later on elements which matched to
459 // elements of container A so we don't modify container B
461 *tmpContB = *(b.TrackContainer());
462 for (
463 TrigMuonEFInfoTrackContainer::const_iterator TrkItrA = a.TrackContainer()->begin();
464 TrkItrA != a.TrackContainer()->end();
465 ++TrkItrA
466 )
467 {
468 // find match in containerB
469 TrigMuonEFInfoTrackContainer::iterator TrkItrB = tmpContB->begin();
470 while ( TrkItrB != tmpContB->end() ) {
471 if (*(*TrkItrB)==*(*TrkItrA)) {
472 // if match rm element from tmp container and break loop
473 tmpContB->erase(TrkItrB);
474 break;
475 }
476 ++TrkItrB;
477 }
478 }
479
480 // if all elements were matched tmp container must be empty
481 bool result = tmpContB->empty();
482 // delete tmp container
483 delete tmpContB;
484 // check result
485 if(!result) return false;
486 }
487 if (a.hasLegacyTrack() && b.hasLegacyTrack()) {
488 if( !(*( a.legacySpectrometerTrack() ) == *( b.legacySpectrometerTrack() ) ) )
489 return false;
490 if( !(*( a.legacyExtrapolatedTrack() ) == *( b.legacyExtrapolatedTrack() ) ) )
491 return false;
492 if( !(*( a.legacyCombinedTrack() ) == *( b.legacyCombinedTrack() ) ) )
493 return false;
494
495 }
496 return true;
497}
498
499void diff( const TrigMuonEFInfo& a, const TrigMuonEFInfo& b,
500 std::map<std::string, double>& variableChange ) {
501
502 if( a.RoINum() != b.RoINum() ) {
503 variableChange[ "RoINum" ] = static_cast< double >( a.RoINum() - b.RoINum() );
504 }
505 if( a.NSegments() != b.NSegments() ) {
506 variableChange[ "NSegments" ] = static_cast< double >( a.NSegments() -
507 b.NSegments() );
508 }
509 if( a.NMdtHits() != b.NMdtHits() ) {
510 variableChange[ "NMdtHits" ] = static_cast< double >( a.NMdtHits() -
511 b.NMdtHits() );
512 }
513 if( a.NRpcHits() != b.NRpcHits() ) {
514 variableChange[ "NRpcHits" ] = static_cast< double >( a.NRpcHits() -
515 b.NRpcHits() );
516 }
517 if( a.NCscHits() != b.NCscHits() ) {
518 variableChange[ "NCscHits" ] = static_cast< double >( a.NCscHits() -
519 b.NCscHits() );
520 }
521 if( a.NTgcHits() != b.NTgcHits() ) {
522 variableChange[ "NTgcHits" ] = static_cast< double >( a.NTgcHits() -
523 b.NTgcHits() );
524 }
525 if( a.EtaPreviousLevel() != b.EtaPreviousLevel() ) {
526 variableChange[ "EtaPreviousLevel" ] = static_cast< double >( a.EtaPreviousLevel() -
527 b.EtaPreviousLevel() );
528 }
529 if( a.PhiPreviousLevel() != b.PhiPreviousLevel() ) {
530 variableChange[ "PhiPreviousLevel" ] = static_cast< double >( a.PhiPreviousLevel() -
531 b.PhiPreviousLevel() );
532 }
533 // simple check on number of tracks in container
534 if (
535 (a.hasTrack() && b.hasTrack())
536 &&
537 (a.TrackContainer()->size() != b.TrackContainer()->size())
538 ) {
539 variableChange[ "NTracks" ] = static_cast< double >(a.TrackContainer()->size() -
540 b.TrackContainer()->size() );
541 }
542 // make a view copy of container B to rm later on elements which matched to
543 // elements of container A so we don't modify container B
545 *tmpContB = *(b.TrackContainer());
546
547 for (
548 TrigMuonEFInfoTrackContainer::const_iterator TrkItrA = a.TrackContainer()->begin();
549 TrkItrA != a.TrackContainer()->end();
550 ++TrkItrA
551 )
552 {
553 // find match in containerB
554 TrigMuonEFInfoTrackContainer::iterator TrkItrB = tmpContB->begin();
555 while ( TrkItrB != tmpContB->end() ) {
556
557 if (*(*TrkItrB)==*(*TrkItrA)) {
558 // if match rm element from tmp container, diff, and break loop
559 diff( *( (*TrkItrA)->SpectrometerTrack() ), *( (*TrkItrB)->SpectrometerTrack() ), variableChange );
560 diff( *( (*TrkItrA)->ExtrapolatedTrack() ), *( (*TrkItrB)->ExtrapolatedTrack() ), variableChange );
561 diff( *( (*TrkItrA)->CombinedTrack() ), *( (*TrkItrB)->CombinedTrack() ), variableChange );
562 tmpContB->erase(TrkItrB);
563 break;
564 }
565 ++TrkItrB;
566 }
567 }
568 // clean up
569 delete tmpContB;
570
571 if (a.hasLegacyTrack() && b.hasLegacyTrack()) {
572 diff( *( a.legacySpectrometerTrack() ), *( b.legacySpectrometerTrack() ), variableChange );
573 diff( *( a.legacyExtrapolatedTrack() ), *( b.legacyExtrapolatedTrack() ), variableChange );
574 diff( *( a.legacyCombinedTrack() ), *( b.legacyCombinedTrack() ), variableChange );
575 }
576
577 return;
578}
static Double_t a
static Double_t ss
MsgStream & operator<<(MsgStream &m, const TrigMuonEFInfo &d)
Helper operator for printing the object.
void diff(const TrigMuonEFInfo &a, const TrigMuonEFInfo &b, std::map< std::string, double > &variableChange)
Comparison with feedback.
bool operator==(const TrigMuonEFInfo &a, const TrigMuonEFInfo &b)
Operator comparing two TrigMuonEFInfo objects for equality.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
iterator erase(iterator position)
Remove element at a given position.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool empty() const noexcept
Returns true if the collection is empty.
void setNMdtHits(unsigned short int theNMdtHits)
TrigMuonEFCbTrack * CombinedTrack()
bool hasExtrapolatedTrack() const
void setExtrapolatedTrack(TrigMuonEFTrack *track)
void addTrack(TrigMuonEFInfoTrack *track)
void setNRpcHits(unsigned short int theNRpcHits)
TrigMuonEFTrack * SpectrometerTrack()
void setRoINum(unsigned short int theRoINum)
bool hasSpectrometerTrack() const
~TrigMuonEFInfo()
Destructor.
bool hasLegacyTrack() const
TrigMuonEFCbTrack * m_combinedTrack
void setPhiPreviousLevel(double thePhiPreviousLevel)
TrigMuonEFInfo & operator=(const TrigMuonEFInfo &rhs)
Assignment operator.
void setNSegments(unsigned short int theNSegments)
unsigned short int m_nRpcHits
double m_etaPreviousLevel
void setEtaPreviousLevel(double theEtaPreviousLevel)
bool hasCombinedTrack() const
unsigned short int m_nCscHits
unsigned short int m_roi
TrigMuonEFTrack * m_extrapolatedTrack
bool hasTrack() const
unsigned short int m_nMdtHits
void setCombinedTrack(TrigMuonEFCbTrack *track)
void setNTgcHits(unsigned short int theNTgcHits)
unsigned short int m_nSegments
TrigMuonEFInfoTrackContainer * m_trackContainer
TrigMuonEFTrack * m_spectrometerTrack
unsigned short int m_nTgcHits
void setNCscHits(unsigned short int theNCscHits)
double m_phiPreviousLevel
TrigMuonEFInfo()
Default constructor.
void setSpectrometerTrack(TrigMuonEFTrack *track)
TrigMuonEFTrack * ExtrapolatedTrack()
static std::string release
Definition computils.h:50
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)