ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Commission
CommissionRec
src
CosmicTriggerTimeTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
CosmicTriggerTimeTool.h
"
6
#include "
CommissionEvent/ComTime.h
"
7
#include "GaudiKernel/IIncidentSvc.h"
8
9
#include "
TrackRecord/TrackRecordCollection.h
"
10
#include "
TrackRecord/TrackRecord.h
"
11
12
#include "
LArSimEvent/LArHitContainer.h
"
13
14
#include "CLHEP/Vector/ThreeVector.h"
15
16
CosmicTriggerTimeTool::CosmicTriggerTimeTool
(
const
std::string&
type
,
17
const
std::string& name,
18
const
IInterface* parent) :
19
base_class(
type
,name,parent),
m_time
(0),
m_newEvent
(true),
20
m_comTime
(0) ,
m_useLArTime
(false)
21
{
22
23
declareProperty(
"UseLArTime"
,
m_useLArTime
);
24
25
}
26
27
28
StatusCode
CosmicTriggerTimeTool::initialize
()
29
{
30
31
ServiceHandle<IIncidentSvc>
incsvc(
"IncidentSvc"
, name());
32
CHECK
( incsvc.retrieve() );
33
34
long
int
pri=100;
35
incsvc->addListener(
this
,
"BeginEvent"
,pri);
36
37
ATH_MSG_DEBUG
(
"CosmicTriggerTimeTool initialized"
);
38
39
return
StatusCode::SUCCESS;
40
41
}
42
43
44
void
CosmicTriggerTimeTool::handle
(
const
Incident&
/* incident */
)
45
{
46
47
ATH_MSG_DEBUG
(
"handle called"
);
48
49
m_newEvent
= true ;
50
m_comTime
= 0 ;
51
return ;
52
}
53
54
55
double
CosmicTriggerTimeTool::trackRecordTime
()
56
{
57
58
// const TimedTrackRecordCollection* coll;
59
const
TrackRecordCollection
* coll =
nullptr
;
60
StatusCode
sc
= evtStore()->retrieve(coll,
"CaloMuonRecorder"
);
61
if
(
sc
!=StatusCode::SUCCESS) {
62
ATH_MSG_ERROR
(
"can not retrieve CaloMuonRecorder"
);
63
return
0;
64
}
65
66
int
n = coll->
size
() ;
67
68
if
( 0 == n ) {
69
ATH_MSG_WARNING
(
"size of CaloMuonRecorder == 0"
);
70
return
0;
71
}
72
73
double
t = 0;
74
for
(
const
TrackRecord
&
r
: *coll) {
75
CLHEP::Hep3Vector pos =
r
.GetPosition();
76
CLHEP::Hep3Vector p =
r
.GetMomentum();
77
ATH_MSG_DEBUG
(
"TrackRecord xyz position "
<<pos.x()<<
" "
78
<< pos.y() <<
" "
<< pos.z() );
79
ATH_MSG_DEBUG
(
" momentum "
<<p.x() <<
" "
80
<< p.y() <<
" "
<< p.z() );
81
ATH_MSG_DEBUG
(
" time "
<<
r
.GetTime() );
82
t +=
r
.GetTime();
83
}
84
85
t = t/n ;
86
87
ATH_MSG_DEBUG
(
"Average time from track record = "
<< t );
88
89
return
t ;
90
91
}
92
93
94
double
CosmicTriggerTimeTool::time
()
95
{
96
97
if
(!
m_newEvent
)
return
m_time
;
98
99
// new event, try to get it from LArTime
100
if
(
m_useLArTime
) {
101
// double t1 = trackRecordTime();
102
m_time
=
larTime
() ;
103
}
104
else
if
(
m_comTime
) {
105
m_time
=
m_comTime
->getTime() ;
106
ATH_MSG_DEBUG
(
"got time from ComTime "
<<
m_time
);
107
}
108
else
if
( StatusCode::SUCCESS == evtStore()->retrieve(
m_comTime
) ) {
109
m_time
=
m_comTime
->getTime() ;
110
ATH_MSG_DEBUG
(
"retrieved ComTime, t= "
<<
m_time
);
111
}
112
else
{
113
// double t1 = trackRecordTime();
114
m_time
=
larTime
() ;
115
}
116
117
m_newEvent
=
false
;
118
return
m_time
;
119
}
120
121
122
double
CosmicTriggerTimeTool::larTime
()
123
{
124
125
std::vector<std::string> keys ;
126
keys.push_back(
"LArHitEMB"
) ;
127
keys.push_back(
"LArHitEMEC"
) ;
128
keys.push_back(
"LArHitHEC"
) ;
129
keys.push_back(
"LArHitFCAL"
) ;
130
131
std::vector<std::string>::const_iterator it = keys.begin() ;
132
std::vector<std::string>::const_iterator it_e = keys.end() ;
133
double
te = 0;
134
double
e = 0;
135
int
n=0;
136
137
for
(;it!=it_e;++it) {
138
const
LArHitContainer
* cont;
139
140
CHECK
( evtStore()->retrieve(cont,(*it)), 0 );
141
142
LArHitContainer::const_iterator
hit_it = cont->
begin
();
143
LArHitContainer::const_iterator
hit_it_e = cont->
end
();
144
for
(;hit_it!=hit_it_e;++hit_it) {
145
const
LArHit
*
hit
= (*hit_it);
146
e +=
hit
->energy();
147
te +=
hit
->energy() *
hit
->time() ;
148
++n;
149
}
150
}
151
152
if
(n==0) {
153
ATH_MSG_INFO
(
"no LArHit in this event"
);
154
return
0;
155
}
156
if
(e==0) {
157
ATH_MSG_INFO
(
"no LArHit energy in this event"
);
158
return
0;
159
}
160
161
double
t = te/e;
162
ATH_MSG_DEBUG
(
"average time from LArHit = "
<<t );
163
164
return
t;
165
}
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
ComTime.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CosmicTriggerTimeTool.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
LArHitContainer.h
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
TrackRecordCollection.h
TrackRecordCollection
AtlasHitsVector< TrackRecord > TrackRecordCollection
Definition
TrackRecordCollection.h:12
TrackRecord.h
AthenaHitsVector::end
const_iterator end() const
Definition
AthenaHitsVector.h:191
AthenaHitsVector::begin
const_iterator begin() const
Definition
AthenaHitsVector.h:187
AthenaHitsVector< LArHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition
AthenaHitsVector.h:105
AtlasHitsVector::size
size_type size() const
Definition
AtlasHitsVector.h:142
CosmicTriggerTimeTool::time
virtual double time() override
returns the time offset of the current trigger
Definition
CosmicTriggerTimeTool.cxx:94
CosmicTriggerTimeTool::m_comTime
const ComTime * m_comTime
Definition
CosmicTriggerTimeTool.h:45
CosmicTriggerTimeTool::CosmicTriggerTimeTool
CosmicTriggerTimeTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition
CosmicTriggerTimeTool.cxx:16
CosmicTriggerTimeTool::m_useLArTime
bool m_useLArTime
Definition
CosmicTriggerTimeTool.h:46
CosmicTriggerTimeTool::initialize
virtual StatusCode initialize() override
Definition
CosmicTriggerTimeTool.cxx:28
CosmicTriggerTimeTool::m_time
double m_time
Definition
CosmicTriggerTimeTool.h:43
CosmicTriggerTimeTool::m_newEvent
bool m_newEvent
Definition
CosmicTriggerTimeTool.h:44
CosmicTriggerTimeTool::handle
virtual void handle(const Incident &incident) override
Definition
CosmicTriggerTimeTool.cxx:44
CosmicTriggerTimeTool::larTime
double larTime()
Definition
CosmicTriggerTimeTool.cxx:122
CosmicTriggerTimeTool::trackRecordTime
double trackRecordTime()
Definition
CosmicTriggerTimeTool.cxx:55
LArHitContainer
Hit collection.
Definition
LArHitContainer.h:26
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition
LArHit.h:25
ServiceHandle
Definition
ClusterMakerTool.h:36
TrackRecord
Definition
TrackRecord.h:12
r
int r
Definition
globals.cxx:22
type
Generated on
for ATLAS Offline Software by
1.17.0