ATLAS Offline Software
Loading...
Searching...
No Matches
CosmicTriggerTimeTool Class Reference

#include <CosmicTriggerTimeTool.h>

Inheritance diagram for CosmicTriggerTimeTool:
Collaboration diagram for CosmicTriggerTimeTool:

Public Member Functions

 CosmicTriggerTimeTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode initialize () override
virtual ~CosmicTriggerTimeTool ()
virtual double time () override
 returns the time offset of the current trigger
virtual void handle (const Incident &incident) override
double larTime ()
double trackRecordTime ()
void setComTime (const ComTime *comTime)

Private Attributes

double m_time
bool m_newEvent
const ComTimem_comTime
bool m_useLArTime

Detailed Description

Definition at line 14 of file CosmicTriggerTimeTool.h.

Constructor & Destructor Documentation

◆ CosmicTriggerTimeTool()

CosmicTriggerTimeTool::CosmicTriggerTimeTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 16 of file CosmicTriggerTimeTool.cxx.

18 :
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}

◆ ~CosmicTriggerTimeTool()

virtual CosmicTriggerTimeTool::~CosmicTriggerTimeTool ( )
inlinevirtual

Definition at line 25 of file CosmicTriggerTimeTool.h.

25{}

Member Function Documentation

◆ handle()

void CosmicTriggerTimeTool::handle ( const Incident & incident)
overridevirtual

Definition at line 44 of file CosmicTriggerTimeTool.cxx.

45{
46
47 ATH_MSG_DEBUG( "handle called" );
48
49 m_newEvent = true ;
50 m_comTime = 0 ;
51 return ;
52}
#define ATH_MSG_DEBUG(x)

◆ initialize()

StatusCode CosmicTriggerTimeTool::initialize ( )
overridevirtual

Definition at line 28 of file CosmicTriggerTimeTool.cxx.

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}
#define CHECK(...)
Evaluate an expression and check for errors.

◆ larTime()

double CosmicTriggerTimeTool::larTime ( )

Definition at line 122 of file CosmicTriggerTimeTool.cxx.

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_INFO(x)
LArHitContainer
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
const_iterator end() const
const_iterator begin() const
double energy() const
Definition LArHit.h:113
double time() const
Definition LArHit.h:118
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ setComTime()

void CosmicTriggerTimeTool::setComTime ( const ComTime * comTime)
inline

Definition at line 35 of file CosmicTriggerTimeTool.h.

36 {
37 m_comTime = comTime;
38 return;
39 }

◆ time()

double CosmicTriggerTimeTool::time ( )
overridevirtual

returns the time offset of the current trigger

Definition at line 94 of file CosmicTriggerTimeTool.cxx.

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}

◆ trackRecordTime()

double CosmicTriggerTimeTool::trackRecordTime ( )

Definition at line 55 of file CosmicTriggerTimeTool.cxx.

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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
AtlasHitsVector< TrackRecord > TrackRecordCollection
size_type size() const
int r
Definition globals.cxx:22
::StatusCode StatusCode
StatusCode definition for legacy code.

Member Data Documentation

◆ m_comTime

const ComTime* CosmicTriggerTimeTool::m_comTime
private

Definition at line 45 of file CosmicTriggerTimeTool.h.

◆ m_newEvent

bool CosmicTriggerTimeTool::m_newEvent
private

Definition at line 44 of file CosmicTriggerTimeTool.h.

◆ m_time

double CosmicTriggerTimeTool::m_time
private

Definition at line 43 of file CosmicTriggerTimeTool.h.

◆ m_useLArTime

bool CosmicTriggerTimeTool::m_useLArTime
private

Definition at line 46 of file CosmicTriggerTimeTool.h.


The documentation for this class was generated from the following files: