ATLAS Offline Software
CosmicTriggerTimeTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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  AthAlgTool(type,name,parent), m_time(0), m_newEvent(true),
20  m_comTime(0) , m_useLArTime(false)
21 {
22 
23  declareInterface<ITriggerTime>(this);
24  declareProperty("UseLArTime", m_useLArTime);
25 
26 }
27 
28 
30 {
31 
32  IIncidentSvc* incsvc;
33  CHECK( service("IncidentSvc",incsvc) );
34 
35  long int pri=100;
36  incsvc->addListener(this,"BeginEvent",pri);
37 
38  ATH_MSG_DEBUG( "CosmicTriggerTimeTool initialized" );
39 
40  return StatusCode::SUCCESS;
41 
42 }
43 
44 
45 void CosmicTriggerTimeTool::handle(const Incident& /* incident */ )
46 {
47 
48  ATH_MSG_DEBUG( "handle called" );
49 
50  m_newEvent = true ;
51  m_comTime = 0 ;
52  return ;
53 }
54 
55 
57 {
58 
59  // const TimedTrackRecordCollection* coll;
60  const TrackRecordCollection* coll = nullptr;
61  StatusCode sc = evtStore()->retrieve(coll,"CaloMuonRecorder");
62  if (sc!=StatusCode::SUCCESS) {
63  ATH_MSG_ERROR( "can not retrieve CaloMuonRecorder" );
64  return 0;
65  }
66 
67  int n = coll->size() ;
68 
69  if ( 0 == n ) {
70  ATH_MSG_WARNING( "size of CaloMuonRecorder == 0" );
71  return 0;
72  }
73 
74  double t = 0;
75  for (auto it : *coll) {
76  // TimedTrackRecord * r = const_cast<TimedTrackRecord*>( *it );
77  CLHEP::Hep3Vector pos = it.GetPosition();
78  CLHEP::Hep3Vector p = it.GetMomentum();
79  // ATH_MSG_DEBUG( "TimedTrackRecord xyz position " <<pos.x()<<" "
80  ATH_MSG_DEBUG( "TrackRecord xyz position " <<pos.x()<<" "
81  << pos.y() << " " << pos.z() );
82  ATH_MSG_DEBUG( " momentum " <<p.x() << " "
83  << p.y() << " " << p.z() );
84  ATH_MSG_DEBUG( " time " << it.GetTime() );
85  t += it.GetTime() ;
86  }
87 
88  t = t/n ;
89 
90  ATH_MSG_DEBUG( "Average time from track record = " << t );
91 
92  return t ;
93 
94 }
95 
96 
98 {
99 
100  if (!m_newEvent) return m_time;
101 
102  // new event, try to get it from LArTime
103  if (m_useLArTime) {
104  // double t1 = trackRecordTime();
105  m_time = larTime() ;
106  }
107  else if ( m_comTime ) {
108  m_time = m_comTime->getTime() ;
109  ATH_MSG_DEBUG( "got time from ComTime "<< m_time );
110  }
111  else if ( StatusCode::SUCCESS == evtStore()->retrieve(m_comTime) ) {
112  m_time = m_comTime->getTime() ;
113  ATH_MSG_DEBUG( "retrieved ComTime, t= "<< m_time );
114  }
115  else {
116  // double t1 = trackRecordTime();
117  m_time = larTime() ;
118  }
119 
120  m_newEvent= false;
121  return m_time;
122 }
123 
124 
126 {
127 
128  std::vector<std::string> keys ;
129  keys.push_back("LArHitEMB") ;
130  keys.push_back("LArHitEMEC") ;
131  keys.push_back("LArHitHEC") ;
132  keys.push_back("LArHitFCAL") ;
133 
134  std::vector<std::string>::const_iterator it = keys.begin() ;
135  std::vector<std::string>::const_iterator it_e = keys.end() ;
136  double te = 0;
137  double e = 0;
138  int n=0;
139 
140  for (;it!=it_e;++it) {
141  const LArHitContainer* cont;
142 
143  CHECK( evtStore()->retrieve(cont,(*it)), 0 );
144 
145  LArHitContainer::const_iterator hit_it = cont->begin();
146  LArHitContainer::const_iterator hit_it_e = cont->end();
147  for (;hit_it!=hit_it_e;++hit_it) {
148  const LArHit * hit = (*hit_it);
149  e += hit->energy();
150  te += hit->energy() * hit->time() ;
151  ++n;
152  }
153  }
154 
155  if (n==0) {
156  ATH_MSG_INFO( "no LArHit in this event" );
157  return 0;
158  }
159  if (e==0) {
160  ATH_MSG_INFO( "no LArHit energy in this event" );
161  return 0;
162  }
163 
164  double t = te/e;
165  ATH_MSG_DEBUG( "average time from LArHit = " <<t );
166 
167  return t;
168 }
CosmicTriggerTimeTool::m_newEvent
bool m_newEvent
Definition: CosmicTriggerTimeTool.h:45
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ComTime.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ComTime::getTime
double getTime() const
Definition: ComTime.h:44
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AtlasHitsVector
Definition: AtlasHitsVector.h:33
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CosmicTriggerTimeTool::larTime
double larTime()
Definition: CosmicTriggerTimeTool.cxx:125
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:47
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:44
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CosmicTriggerTimeTool::m_comTime
const ComTime * m_comTime
Definition: CosmicTriggerTimeTool.h:46
CosmicTriggerTimeTool::initialize
virtual StatusCode initialize()
Definition: CosmicTriggerTimeTool.cxx:29
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::handle
virtual void handle(const Incident &incident)
Definition: CosmicTriggerTimeTool.cxx:45
TrackRecord.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
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:56
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CosmicTriggerTimeTool::time
virtual double time()
returns the time offset of the current trigger
Definition: CosmicTriggerTimeTool.cxx:97
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
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:790
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:143
AthAlgTool
Definition: AthAlgTool.h:26
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:139