ATLAS Offline Software
Loading...
Searching...
No Matches
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
21
22
23
25
26namespace InDet
27{
28 InDetCosmicsEventPhase::InDetCosmicsEventPhase(const std::string& name, ISvcLocator* pSvcLocator) :
29 AthAlgorithm(name, pSvcLocator),
30 m_caldbtool("TRT_CalDbTool", this),
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());
50 ATH_CHECK(m_writeKey_TRTPhase.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}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
abstract interface to TRT calibration constants
static Double_t sc
abstract base class for rt-relations
This is an Identifier helper class for the TRT subdetector.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
InDetCosmicsEventPhase(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< InDet::IInDetCosmicsEventPhaseTool > m_eventPhaseTool
ToolHandle< Trk::ITrackSummaryTool > m_trackSumTool
SG::WriteHandleKey< ComTime > m_writeKey_TRTPhase
ToolHandle< ITRT_CalDbTool > m_caldbtool
TRT Calibration DB tool.
SG::ReadHandleKeyArray< TrackCollection > m_readKey_tracks
Represents 'corrected' measurements from the TRT (for example, corrected for wire sag).
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
This is an Identifier helper class for the TRT subdetector.
Definition TRT_ID.h:82
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition TRT_ID.h:797
This class is the pure abstract base class for all fittable tracking measurements.
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
Identifier identify() const
return the identifier -extends MeasurementBase
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Primary Vertex Finder.