ATLAS Offline Software
Loading...
Searching...
No Matches
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
20ComTimeRec::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));
29 declareProperty("Velocity", m_velocity=299.792458*CLHEP::millimeter/CLHEP::nanosecond);
30}
31
32//----------------------------------------------------------------
33
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
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 const TrackRecord *earliestMuon=nullptr;
88
89 for(const TrackRecord& r : *coll) {
90
91 if(abs(r.GetPDGCode()) == 13 ) {
92 nMuons++;
93 if( (nMuons==1) or (r.GetTime() < earliestMuonTime) ) {
94 earliestMuon = &r;
95 earliestMuonTime = r.GetTime();
96 }
97 }
98 }
99
100 if( nMuons>=1 ) { // use the earliest muon if more than 1
101 CLHEP::Hep3Vector pos = earliestMuon->GetPosition();
102 CLHEP::Hep3Vector mom = earliestMuon->GetMomentum();
103 double energy = sqrt(mom.x()*mom.x() + mom.y()*mom.y() + mom.z()*mom.z());
104
105 CLHEP::Hep3Vector cosThetaDir = CLHEP::Hep3Vector(mom.x()/energy, mom.y()/energy, mom.z()/energy);
106
107 double time = earliestMuon->GetTime();
108
109 ATH_MSG_DEBUG( " Earliest Muon xyz position " << pos.x()<<" "
110 << pos.y() << " " << pos.z() );
111 ATH_MSG_DEBUG( " cosThetaDir " << cosThetaDir.x() << " "
112 << cosThetaDir.y() << " " << cosThetaDir.z() );
113 ATH_MSG_DEBUG( " time " << time );
114
115 // Three different methods of definining the virtrual trigger point
116 // 1) m_method = YZero : extrapolate to Y=0 plane (default)
117 // 2) m_method = ZZero : extrapolate to Z=0 plane
118 // 3) m_method = Origin : extrapolate to closest approach to (0,0,0)
119
120
121 double PathCritical;
122 CLHEP::Hep3Vector PointCritical;
123
124 if( m_method == "YZero" ) { // Extrapolate to Y=0 plane. Good for cosmics.
125 double dXdY = cosThetaDir.x()/cosThetaDir.y();
126 double dZdY = cosThetaDir.z()/cosThetaDir.y();
127
128 double XCritical = pos.x()-dXdY*pos.y();
129 double YCritical = 0.0;
130 double ZCritical = pos.z()-dZdY*pos.y();
131
132 PointCritical = CLHEP::Hep3Vector(XCritical,YCritical,ZCritical);
133
134 PathCritical = sqrt(pow(XCritical-pos.x(),2) + pow(YCritical-pos.y(),2) +
135 pow(ZCritical-pos.z(),2));
136 if( (YCritical-pos.y())*cosThetaDir.y() < 0 ) { // backwards extrapolation??
137 ATH_MSG_WARNING( "Backwards extrapolation?? pos.y(),cosThetaDir.y() = "
138 << pos.y()<<"," << cosThetaDir.y() );
139 PathCritical = -1.0 * PathCritical;
140 }
141 }
142 else if (m_method == "ZZero") { // Extrapolate to Z=0 plane. Good for halo.
143 double dXdZ = cosThetaDir.x()/cosThetaDir.z();
144 double dYdZ = cosThetaDir.y()/cosThetaDir.z();
145
146 double XCritical = pos.x()-dXdZ*pos.z();
147 double YCritical = pos.y()-dYdZ*pos.z();
148 double ZCritical = 0.0;
149
150 PointCritical = CLHEP::Hep3Vector(XCritical,YCritical,ZCritical);
151
152 PathCritical = sqrt(pow(XCritical-pos.x(),2) + pow(YCritical-pos.y(),2) +
153 pow(ZCritical-pos.z(),2));
154 if( (ZCritical-pos.z())*cosThetaDir.z() < 0 ) { // backwards extrapolation??
155 ATH_MSG_WARNING( "Backwards extrapolation?? pos.z(),cosThetaDir.z() = "
156 << pos.z()<<"," << cosThetaDir.z() );
157 PathCritical = -1.0 * PathCritical;
158 }
159 }
160 else if (m_method == "Origin") { // Extrapolate to closest approach to (0,0,0)
161 // See arithmetic in RMcP logbook 28 Feb 2006
162 PathCritical = -1.*(pos.x()*cosThetaDir.x() + pos.y()*cosThetaDir.y() +
163 pos.z()*cosThetaDir.z());
164 PointCritical = CLHEP::Hep3Vector( pos.x() + PathCritical*cosThetaDir.x(),
165 pos.y() + PathCritical*cosThetaDir.y(),
166 pos.z() + PathCritical*cosThetaDir.z());
167 }
168 else { // This is bad ... invalid method requested
169 ATH_MSG_FATAL( "Invalid method = " << m_method );
170 return StatusCode::FAILURE;
171 }
172
173 double TimeCritical = time + PathCritical/m_velocity;
174 double TTCTime = m_samplingPeriod * floor(TimeCritical/m_samplingPeriod);
175
176 ATH_MSG_DEBUG( " Extrapolated muon xyz position " << PointCritical.x()<<" "
177 << PointCritical.y()<<" " << PointCritical.z());
178 ATH_MSG_DEBUG( " path " << PathCritical );
179 ATH_MSG_DEBUG( " time " << TimeCritical );
180 ATH_MSG_DEBUG( " TTCTime " << TTCTime );
181
182 ComTime* theComTime = new ComTime(TTCTime,TimeCritical,PointCritical,cosThetaDir);
183 CHECK( evtStore()->record(theComTime, m_comTimeKey) );
184
185 m_triggerTimeTool->setComTime(theComTime);
186
187 } else { // no muons entering cavern found.
188 ATH_MSG_DEBUG( " No muons entered cavern." );
189 ComTime *theComTime = new ComTime();
190 CHECK( evtStore()->record(theComTime, m_comTimeKey) );
191 }
192 } else if(m_mode == "CollisionMode" ) {
193 // Using cosmic reco during collisions. Fire on BCIDs.
194 // Just provide a default ComTime object.
195 ComTime *theComTime = new ComTime();
196 CHECK( evtStore()->record(theComTime, m_comTimeKey) );
197 return StatusCode::SUCCESS;
198 } else {
199 ATH_MSG_FATAL( "Invalid mode = " << m_mode );
200 return StatusCode::SUCCESS;
201 }
202 return StatusCode::SUCCESS;
203}
204
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(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.
AtlasHitsVector< TrackRecord > TrackRecordCollection
constexpr int pow(int base, int exp) noexcept
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::string m_method
Definition ComTimeRec.h:27
double m_samplingPeriod
Definition ComTimeRec.h:29
double m_velocity
Definition ComTimeRec.h:30
std::string m_comTimeKey
Definition ComTimeRec.h:25
CosmicTriggerTimeTool * m_triggerTimeTool
Definition ComTimeRec.h:31
std::string m_TTRKey
Definition ComTimeRec.h:28
std::string m_mode
Definition ComTimeRec.h:26
virtual StatusCode execute() override
virtual StatusCode initialize() override
ComTimeRec(const std::string &name, ISvcLocator *pSvcLocator)
CLHEP::Hep3Vector GetPosition() const
Position.
Definition TrackRecord.h:88
CLHEP::Hep3Vector GetMomentum() const
Momentum.
Definition TrackRecord.h:94
double GetTime() const
Time.
int r
Definition globals.cxx:22
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114