ATLAS Offline Software
CosmicTriggerTimeTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "GaudiKernel/IIncidentSvc.h"
8 
10 #include "TrackRecord/TrackRecord.h"
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 
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 
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 (auto it : *coll) {
75  // TimedTrackRecord * r = const_cast<TimedTrackRecord*>( *it );
76  CLHEP::Hep3Vector pos = it.GetPosition();
77  CLHEP::Hep3Vector p = it.GetMomentum();
78  // ATH_MSG_DEBUG( "TimedTrackRecord xyz position " <<pos.x()<<" "
79  ATH_MSG_DEBUG( "TrackRecord xyz position " <<pos.x()<<" "
80  << pos.y() << " " << pos.z() );
81  ATH_MSG_DEBUG( " momentum " <<p.x() << " "
82  << p.y() << " " << p.z() );
83  ATH_MSG_DEBUG( " time " << it.GetTime() );
84  t += it.GetTime() ;
85  }
86 
87  t = t/n ;
88 
89  ATH_MSG_DEBUG( "Average time from track record = " << t );
90 
91  return t ;
92 
93 }
94 
95 
97 {
98 
99  if (!m_newEvent) return m_time;
100 
101  // new event, try to get it from LArTime
102  if (m_useLArTime) {
103  // double t1 = trackRecordTime();
104  m_time = larTime() ;
105  }
106  else if ( m_comTime ) {
107  m_time = m_comTime->getTime() ;
108  ATH_MSG_DEBUG( "got time from ComTime "<< m_time );
109  }
110  else if ( StatusCode::SUCCESS == evtStore()->retrieve(m_comTime) ) {
111  m_time = m_comTime->getTime() ;
112  ATH_MSG_DEBUG( "retrieved ComTime, t= "<< m_time );
113  }
114  else {
115  // double t1 = trackRecordTime();
116  m_time = larTime() ;
117  }
118 
119  m_newEvent= false;
120  return m_time;
121 }
122 
123 
125 {
126 
127  std::vector<std::string> keys ;
128  keys.push_back("LArHitEMB") ;
129  keys.push_back("LArHitEMEC") ;
130  keys.push_back("LArHitHEC") ;
131  keys.push_back("LArHitFCAL") ;
132 
133  std::vector<std::string>::const_iterator it = keys.begin() ;
134  std::vector<std::string>::const_iterator it_e = keys.end() ;
135  double te = 0;
136  double e = 0;
137  int n=0;
138 
139  for (;it!=it_e;++it) {
140  const LArHitContainer* cont;
141 
142  CHECK( evtStore()->retrieve(cont,(*it)), 0 );
143 
144  LArHitContainer::const_iterator hit_it = cont->begin();
145  LArHitContainer::const_iterator hit_it_e = cont->end();
146  for (;hit_it!=hit_it_e;++hit_it) {
147  const LArHit * hit = (*hit_it);
148  e += hit->energy();
149  te += hit->energy() * hit->time() ;
150  ++n;
151  }
152  }
153 
154  if (n==0) {
155  ATH_MSG_INFO( "no LArHit in this event" );
156  return 0;
157  }
158  if (e==0) {
159  ATH_MSG_INFO( "no LArHit energy in this event" );
160  return 0;
161  }
162 
163  double t = te/e;
164  ATH_MSG_DEBUG( "average time from LArHit = " <<t );
165 
166  return t;
167 }
CosmicTriggerTimeTool::m_newEvent
bool m_newEvent
Definition: CosmicTriggerTimeTool.h:44
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
CosmicTriggerTimeTool::initialize
virtual StatusCode initialize() override
Definition: CosmicTriggerTimeTool.cxx:28
ComTime.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ComTime::getTime
double getTime() const
Definition: ComTime.h:44
AtlasHitsVector
Definition: AtlasHitsVector.h:33
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CosmicTriggerTimeTool::larTime
double larTime()
Definition: CosmicTriggerTimeTool.cxx:124
LArHit::energy
double energy() const
Definition: LArHit.h:113
LArHitContainer
Hit collection.
Definition: LArHitContainer.h:26
CosmicTriggerTimeTool::m_useLArTime
bool m_useLArTime
Definition: CosmicTriggerTimeTool.h:46
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthenaHitsVector< LArHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:58
CosmicTriggerTimeTool::m_time
double m_time
Definition: CosmicTriggerTimeTool.h:43
CosmicTriggerTimeTool::m_comTime
const ComTime * m_comTime
Definition: CosmicTriggerTimeTool.h:45
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
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
LArHit::time
double time() const
Definition: LArHit.h:118
CosmicTriggerTimeTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CosmicTriggerTimeTool::time
virtual double time() override
returns the time offset of the current trigger
Definition: CosmicTriggerTimeTool.cxx:96
TrackRecord.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrackRecordCollection.h
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition: LArHit.h:25
CosmicTriggerTimeTool::trackRecordTime
double trackRecordTime()
Definition: CosmicTriggerTimeTool.cxx:55
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArHitContainer.h
CosmicTriggerTimeTool::CosmicTriggerTimeTool
CosmicTriggerTimeTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CosmicTriggerTimeTool.cxx:16
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:143
CosmicTriggerTimeTool::handle
virtual void handle(const Incident &incident) override
Definition: CosmicTriggerTimeTool.cxx:44
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:139
ServiceHandle< IIncidentSvc >