ATLAS Offline Software
Loading...
Searching...
No Matches
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
7#include "GaudiKernel/IIncidentSvc.h"
8
11
13
14#include "CLHEP/Vector/ThreeVector.h"
15
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
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
44void 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
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
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
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
AtlasHitsVector< TrackRecord > TrackRecordCollection
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
const_iterator end() const
const_iterator begin() const
size_type size() const
virtual double time() override
returns the time offset of the current trigger
CosmicTriggerTimeTool(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode initialize() override
virtual void handle(const Incident &incident) override
Hit collection.
Class to store hit energy and time in LAr cell from G4 simulation.
Definition LArHit.h:25
double energy() const
Definition LArHit.h:113
double time() const
Definition LArHit.h:118
int r
Definition globals.cxx:22