ATLAS Offline Software
InDetCosmicsEventPhase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include "TrkTrack/Track.h"
9 
11 
13 #include "GaudiKernel/TypeNameString.h"
14 
20 #include "InDetIdentifier/TRT_ID.h"
21 
22 
23 
25 
26 namespace InDet
27 {
28  InDetCosmicsEventPhase::InDetCosmicsEventPhase(const std::string& name, ISvcLocator* pSvcLocator) :
29  AthAlgorithm(name, pSvcLocator),
30  m_caldbtool("TRT_CalDbTool", this),
31  m_eventPhaseTool() {
32  declareProperty("TRTCalDbTool", m_caldbtool);
33  declareProperty("TrackSummaryTool", m_trackSumTool);
34  declareProperty("EventPhaseTool", m_eventPhaseTool);
35  }
36 
38  ATH_MSG_INFO("initialize()");
39 
40  StatusCode sc = m_caldbtool.retrieve();
41  if (sc.isFailure()) {
42  ATH_MSG_FATAL("Failed to retrieve TRT Calibration DB Service!");
43  return sc;
44  }
45 
46  ATH_CHECK(m_eventPhaseTool.retrieve());
47  m_trackSumTool.disable(); // never used?
48 
49  ATH_CHECK(m_readKey_tracks.initialize());
51 
52  return StatusCode::SUCCESS;
53  }
54 
55 
57 
58  m_phase = 0;
59 
60  const Trk::Track* selected = nullptr;
61  int maxTRT = -1;
62 
63 // Sasa Nov 30
64 
65  const TRT_ID* TRTHelper = nullptr;
66  StatusCode sc = detStore()->retrieve(TRTHelper, "TRT_ID");
67  if (sc.isFailure()) {
68  msg(MSG::ERROR) << "Unable to retrieve TRT ID Helper." << endmsg;
69  return sc;
70  }
71 
72  std::vector<double> EPforTracksWithBarrelHits;
73 
75  SG::ReadHandle<TrackCollection> MyTrackCollection(k);
76  if (MyTrackCollection.isValid()) {
77  const TrackCollection* trtbarreltracks = MyTrackCollection.cptr();
78  TrackCollection::const_iterator trackIt = trtbarreltracks->begin();
79  TrackCollection::const_iterator trackEnd = trtbarreltracks->end();
80  for (; trackIt != trackEnd; ++trackIt) {
81  int nTRTbarrelHits = 0;
82  Trk::Track const* track = *trackIt;
83  for (Trk::TrackStateOnSurface const* state : *track->trackStateOnSurfaces()) {
84  Trk::MeasurementBase const* mesb = state->measurementOnTrack();
85  if (!mesb || !state->type(Trk::TrackStateOnSurface::Measurement)) continue;
86  InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
87  if (!trtcirc) continue;
88  Identifier const& id = trtcirc->identify();
89  if (abs(TRTHelper->barrel_ec(id)) != 1) continue;
90  nTRTbarrelHits++;
91  }
92 
93  if (nTRTbarrelHits >= 10) { // require at least 10 barrel TRT hits
94  double tmpEP = m_eventPhaseTool->findPhase(track);
95  if (tmpEP != 0.) EPforTracksWithBarrelHits.push_back(tmpEP);
96  }
97 
98  if (nTRTbarrelHits > maxTRT) {
99  maxTRT = nTRTbarrelHits;
100  selected = *trackIt; // track with max N of barrel hits
101  }
102  }
103  }
104  }
105 
106  m_phase = 0.;
107 
108  if (0 && selected) { // used to be default in cosmic to use only one track
109  ATH_MSG_DEBUG("Using track with " << maxTRT << " TRT Hits");
110  m_phase = m_eventPhaseTool->findPhase(selected);
111  }
112 
113 // Sasa Dec 2009: use average instead of result for one track
114  if (EPforTracksWithBarrelHits.size()) {
115  for (unsigned int i = 0; i < EPforTracksWithBarrelHits.size(); i++) m_phase += EPforTracksWithBarrelHits[i];
116  m_phase /= (double) (EPforTracksWithBarrelHits.size());
117  }
118 
119  ATH_MSG_DEBUG("Event Phase - " << m_phase);
120 
121  sc = storePhase();
122 
123  ATH_MSG_DEBUG("exit InDetCosmicsEventPhase");
124  sc = StatusCode::SUCCESS;
125  return sc;
126  }
127 
129  ATH_MSG_INFO("finalize()");
130  return StatusCode::SUCCESS;
131  }
132 
134  ATH_MSG_DEBUG("Recording phase... " << m_phase);
136  writeTRTPhase = std::make_unique<ComTime>(m_phase, m_phase);
137  ATH_CHECK(writeTRTPhase.isValid());
138  return StatusCode::SUCCESS;
139  }
140 }
ITrackSummaryTool.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
RtRelation.h
abstract base class for rt-relations
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::InDetCosmicsEventPhase::initialize
StatusCode initialize()
Definition: InDetCosmicsEventPhase.cxx:37
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
InDet::InDetCosmicsEventPhase::InDetCosmicsEventPhase
InDetCosmicsEventPhase(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InDetCosmicsEventPhase.cxx:28
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
BasicRtRelation.h
InDet::TRT_DriftCircleOnTrack
Definition: TRT_DriftCircleOnTrack.h:53
InDet::InDetCosmicsEventPhase::m_eventPhaseTool
ToolHandle< InDet::IInDetCosmicsEventPhaseTool > m_eventPhaseTool
Definition: InDetCosmicsEventPhase.h:44
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
InDet::InDetCosmicsEventPhase::m_readKey_tracks
SG::ReadHandleKeyArray< TrackCollection > m_readKey_tracks
Definition: InDetCosmicsEventPhase.h:39
Track.h
InDet::InDetCosmicsEventPhase::m_writeKey_TRTPhase
SG::WriteHandleKey< ComTime > m_writeKey_TRTPhase
Definition: InDetCosmicsEventPhase.h:40
lumiFormat.i
int i
Definition: lumiFormat.py:85
InDetCosmicsEventPhase.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
TrackCollection.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::MeasurementBase::type
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
ITRT_CalDbTool.h
abstract interface to TRT calibration constants
TrackSummary.h
InDet::InDetCosmicsEventPhase::m_caldbtool
ToolHandle< ITRT_CalDbTool > m_caldbtool
TRT Calibration DB tool.
Definition: InDetCosmicsEventPhase.h:42
TRT_DriftCircleOnTrack.h
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
DataVector< Trk::Track >
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::MeasurementBase
Definition: MeasurementBase.h:58
InDet::InDetCosmicsEventPhase::execute
StatusCode execute()
Definition: InDetCosmicsEventPhase.cxx:56
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
InDet::InDetCosmicsEventPhase::m_phase
double m_phase
Definition: InDetCosmicsEventPhase.h:37
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TRT_ID
Definition: TRT_ID.h:84
Trk::RIO_OnTrack::identify
Identifier identify() const
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:152
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
InDet::InDetCosmicsEventPhase::finalize
StatusCode finalize()
Definition: InDetCosmicsEventPhase.cxx:128
InDet::InDetCosmicsEventPhase::m_trackSumTool
ToolHandle< Trk::ITrackSummaryTool > m_trackSumTool
Definition: InDetCosmicsEventPhase.h:43
InDet::InDetCosmicsEventPhase::storePhase
StatusCode storePhase()
Definition: InDetCosmicsEventPhase.cxx:133
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
SegmentCollection.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
fitman.k
k
Definition: fitman.py:528
Identifier
Definition: IdentifierFieldParser.cxx:14