Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ComTimeRec.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ComTimeRec.h"
6 
7 #include "CLHEP/Units/SystemOfUnits.h"
8 
9 #include "Gaudi/Property.h"
10 
12 
15 
16 #include <algorithm>
17 
18 //----------------------------------------------------------------
19 
20 ComTimeRec::ComTimeRec(const std::string& name,
21  ISvcLocator* pSvcLocator) :
22  AthAlgorithm(name,pSvcLocator),m_triggerTimeTool(0)
23 {
24  declareProperty("ComTimeKey",m_comTimeKey="ComTime");
25  declareProperty("Mode",m_mode="TTRCavern");
26  declareProperty("Method",m_method="YZero"); // or "ZZero" or "Origin"
27  declareProperty("TTRKey",m_TTRKey="CosmicRecord");
28  declareProperty("SamplingPeriod",m_samplingPeriod=1./(40.08*CLHEP::megahertz));
30 }
31 
32 //----------------------------------------------------------------
33 
35 {
36 }
37 
38 //----------------------------------------------------------------
39 
41 {
42 
43  ATH_MSG_INFO( "In initialize()" );
44 
45  // This level of obfuscation is necessary because ITriggerTime, the interface class for
46  // the timing tool, does not provide the method that is needed here (which is bad design).
47  // The right thing to do is to fix the interface, at which point this is a simple retrieve.
48  // Until then, we are stuck with the old way.
49 
50  IAlgTool *trigTool(0);
51  CHECK( toolSvc()->retrieveTool("CosmicTriggerTimeTool",trigTool) );
52 
53  m_triggerTimeTool = dynamic_cast<CosmicTriggerTimeTool*>(trigTool);
54  if(0==m_triggerTimeTool){
55  ATH_MSG_ERROR( " Failed to dynamic cast CosmicTriggerTimeTool " );
56  return StatusCode::FAILURE;
57  }
58 
59  return StatusCode::SUCCESS;
60 
61 }
62 
63 //----------------------------------------------------------------
64 
66 {
67 
68  ATH_MSG_DEBUG( "In execute()" );
69 
70  // Pick method of calculating trigger point.
71  if(m_mode == "TTRCavern" ) {
72 
73  // Use the Timed Track Record of the muon entering the cavern.
74 
75  if(!evtStore()->contains<TrackRecordCollection>(m_TTRKey) ){
76  ATH_MSG_ERROR( " can not retrieve TrackRecordCollection with key " << m_TTRKey );
77  // Put default ComTime into SG for.
78  ComTime *theComTime = new ComTime();
79  CHECK( evtStore()->record(theComTime, m_comTimeKey) );
80  return StatusCode::SUCCESS;
81  }
82  // const TimedTrackRecordCollection* coll;
83  const TrackRecordCollection *coll(NULL);
84  CHECK( evtStore()->retrieve(coll, m_TTRKey) );
85  int nMuons = 0;
86  double earliestMuonTime = -1.;
87  // TimedTrackRecord* earliestMuon=NULL;
88  TrackRecord *earliestMuon=nullptr;
89 
90  for(auto it : *coll) {
91 
92  if(abs(it.GetPDGCode()) == 13 ) {
93  nMuons++;
94  if( (nMuons==1) or (it.GetTime() < earliestMuonTime) ) {
95  // earliestMuon = const_cast<TimedTrackRecord*>(*it);
96  earliestMuon = &it;
97  earliestMuonTime = it.GetTime();
98  }
99  }
100  }
101 
102  if( nMuons>=1 ) { // use the earliest muon if more than 1
103  CLHEP::Hep3Vector pos = earliestMuon->GetPosition();
104  CLHEP::Hep3Vector mom = earliestMuon->GetMomentum();
105  double energy = sqrt(mom.x()*mom.x() + mom.y()*mom.y() + mom.z()*mom.z());
106 
107  CLHEP::Hep3Vector cosThetaDir = CLHEP::Hep3Vector(mom.x()/energy, mom.y()/energy, mom.z()/energy);
108 
109  double time = earliestMuon->GetTime();
110 
111  ATH_MSG_DEBUG( " Earliest Muon xyz position " << pos.x()<<" "
112  << pos.y() << " " << pos.z() );
113  ATH_MSG_DEBUG( " cosThetaDir " << cosThetaDir.x() << " "
114  << cosThetaDir.y() << " " << cosThetaDir.z() );
115  ATH_MSG_DEBUG( " time " << time );
116 
117  // Three different methods of definining the virtrual trigger point
118  // 1) m_method = YZero : extrapolate to Y=0 plane (default)
119  // 2) m_method = ZZero : extrapolate to Z=0 plane
120  // 3) m_method = Origin : extrapolate to closest approach to (0,0,0)
121 
122 
123  double PathCritical;
124  CLHEP::Hep3Vector PointCritical;
125 
126  if( m_method == "YZero" ) { // Extrapolate to Y=0 plane. Good for cosmics.
127  double dXdY = cosThetaDir.x()/cosThetaDir.y();
128  double dZdY = cosThetaDir.z()/cosThetaDir.y();
129 
130  double XCritical = pos.x()-dXdY*pos.y();
131  double YCritical = 0.0;
132  double ZCritical = pos.z()-dZdY*pos.y();
133 
134  PointCritical = CLHEP::Hep3Vector(XCritical,YCritical,ZCritical);
135 
136  PathCritical = sqrt(pow(XCritical-pos.x(),2) + pow(YCritical-pos.y(),2) +
137  pow(ZCritical-pos.z(),2));
138  if( (YCritical-pos.y())*cosThetaDir.y() < 0 ) { // backwards extrapolation??
139  ATH_MSG_WARNING( "Backwards extrapolation?? pos.y(),cosThetaDir.y() = "
140  << pos.y()<<"," << cosThetaDir.y() );
141  PathCritical = -1.0 * PathCritical;
142  }
143  }
144  else if (m_method == "ZZero") { // Extrapolate to Z=0 plane. Good for halo.
145  double dXdZ = cosThetaDir.x()/cosThetaDir.z();
146  double dYdZ = cosThetaDir.y()/cosThetaDir.z();
147 
148  double XCritical = pos.x()-dXdZ*pos.z();
149  double YCritical = pos.y()-dYdZ*pos.z();
150  double ZCritical = 0.0;
151 
152  PointCritical = CLHEP::Hep3Vector(XCritical,YCritical,ZCritical);
153 
154  PathCritical = sqrt(pow(XCritical-pos.x(),2) + pow(YCritical-pos.y(),2) +
155  pow(ZCritical-pos.z(),2));
156  if( (ZCritical-pos.z())*cosThetaDir.z() < 0 ) { // backwards extrapolation??
157  ATH_MSG_WARNING( "Backwards extrapolation?? pos.z(),cosThetaDir.z() = "
158  << pos.z()<<"," << cosThetaDir.z() );
159  PathCritical = -1.0 * PathCritical;
160  }
161  }
162  else if (m_method == "Origin") { // Extrapolate to closest approach to (0,0,0)
163  // See arithmetic in RMcP logbook 28 Feb 2006
164  PathCritical = -1.*(pos.x()*cosThetaDir.x() + pos.y()*cosThetaDir.y() +
165  pos.z()*cosThetaDir.z());
166  PointCritical = CLHEP::Hep3Vector( pos.x() + PathCritical*cosThetaDir.x(),
167  pos.y() + PathCritical*cosThetaDir.y(),
168  pos.z() + PathCritical*cosThetaDir.z());
169  }
170  else { // This is bad ... invalid method requested
171  ATH_MSG_FATAL( "Invalid method = " << m_method );
172  return StatusCode::FAILURE;
173  }
174 
175  double TimeCritical = time + PathCritical/m_velocity;
176  double TTCTime = m_samplingPeriod * floor(TimeCritical/m_samplingPeriod);
177 
178  ATH_MSG_DEBUG( " Extrapolated muon xyz position " << PointCritical.x()<<" "
179  << PointCritical.y()<<" " << PointCritical.z());
180  ATH_MSG_DEBUG( " path " << PathCritical );
181  ATH_MSG_DEBUG( " time " << TimeCritical );
182  ATH_MSG_DEBUG( " TTCTime " << TTCTime );
183 
184  ComTime* theComTime = new ComTime(TTCTime,TimeCritical,PointCritical,cosThetaDir);
185  CHECK( evtStore()->record(theComTime, m_comTimeKey) );
186 
187  m_triggerTimeTool->setComTime(theComTime);
188 
189  } else { // no muons entering cavern found.
190  ATH_MSG_DEBUG( " No muons entered cavern." );
191  ComTime *theComTime = new ComTime();
192  CHECK( evtStore()->record(theComTime, m_comTimeKey) );
193  }
194  } else if(m_mode == "CollisionMode" ) {
195  // Using cosmic reco during collisions. Fire on BCIDs.
196  // Just provide a default ComTime object.
197  ComTime *theComTime = new ComTime();
198  CHECK( evtStore()->record(theComTime, m_comTimeKey) );
199  return StatusCode::SUCCESS;
200  } else {
201  ATH_MSG_FATAL( "Invalid mode = " << m_mode );
202  return StatusCode::SUCCESS;
203  }
204  return StatusCode::SUCCESS;
205 }
206 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ComTime.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
python.SystemOfUnits.nanosecond
int nanosecond
Definition: SystemOfUnits.py:119
ComTimeRec::execute
virtual StatusCode execute() override
Definition: ComTimeRec.cxx:65
ComTimeRec.h
ComTimeRec::~ComTimeRec
~ComTimeRec()
Definition: ComTimeRec.cxx:34
AthCommonDataStore< AthCommonMsg< Algorithm > >::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:407
ComTimeRec::initialize
virtual StatusCode initialize() override
Definition: ComTimeRec.cxx:40
ComTime
Definition: ComTime.h:17
ComTimeRec::m_comTimeKey
std::string m_comTimeKey
Definition: ComTimeRec.h:25
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
python.SystemOfUnits.megahertz
int megahertz
Definition: SystemOfUnits.py:127
ComTimeRec::m_TTRKey
std::string m_TTRKey
Definition: ComTimeRec.h:28
TrackRecord::GetTime
double GetTime() const
Time.
Definition: TrackRecord.h:106
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
python.SystemOfUnits.millimeter
int millimeter
Definition: SystemOfUnits.py:53
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
ComTimeRec::m_method
std::string m_method
Definition: ComTimeRec.h:27
TrackRecord::GetPosition
CLHEP::Hep3Vector GetPosition() const
Position.
Definition: TrackRecord.h:88
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
ComTimeRec::m_samplingPeriod
double m_samplingPeriod
Definition: ComTimeRec.h:29
AthAlgorithm
Definition: AthAlgorithm.h:47
TrackRecord.h
CosmicTriggerTimeTool::setComTime
void setComTime(const ComTime *comTime)
Definition: CosmicTriggerTimeTool.h:35
ComTimeRec::m_mode
std::string m_mode
Definition: ComTimeRec.h:26
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TrackRecordCollection.h
TrackRecord::GetMomentum
CLHEP::Hep3Vector GetMomentum() const
Momentum.
Definition: TrackRecord.h:94
TrackRecord
Definition: TrackRecord.h:12
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ComTimeRec::ComTimeRec
ComTimeRec(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ComTimeRec.cxx:20
ComTimeRec::m_triggerTimeTool
CosmicTriggerTimeTool * m_triggerTimeTool
Definition: ComTimeRec.h:31
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ComTimeRec::m_velocity
double m_velocity
Definition: ComTimeRec.h:30
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
CosmicTriggerTimeTool
Definition: CosmicTriggerTimeTool.h:15