ATLAS Offline Software
Loading...
Searching...
No Matches
HitCreatorTRT.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// class header
6#include "HitCreatorTRT.h"
7
8// Framework
9#include "GaudiKernel/ISvcLocator.h"
11// ISF
14// Tracking
16#include "TrkSurfaces/Surface.h"
24// InDet
29// CLHEP
30#include "CLHEP/Units/PhysicalConstants.h"
31#include "CLHEP/Random/RandFlat.h"
32#include "CLHEP/Random/RandGauss.h"
33#include "CLHEP/Random/RandLandau.h"
34
35//================ Constructor =================================================
37 const std::string& n,
38 const IInterface* p ) :
39 base_class(t,n,p)
40{
41}
42
43
44//================ Initialisation =================================================
45
47{
48 // Random number service
49 ATH_CHECK ( m_randomSvc.retrieve() );
50 //Get own engine with own seeds:
52 if (!m_randomEngine) {
53 ATH_MSG_ERROR( "[ --- ] Could not get random engine '" << m_randomEngineName << "'" );
54 return StatusCode::FAILURE;
55 }
56
57 // Tools & Services
58 ATH_CHECK ( m_trtStatusSummaryTool.retrieve( DisableTool{ !m_useConditionsSvc } ) );
59 // Get the TRT Identifier-helper:
60 ATH_CHECK ( detStore()->retrieve(m_trtIdHelper, m_trtIdHelperName) );
61
62 // Athena/Gaudi framework
63 ATH_CHECK ( m_incidentSvc.retrieve() );
64 // register to the incident service: BeginEvent for TrackCollection
65 m_incidentSvc->addListener( this, IncidentType::BeginEvent );
66
67 ATH_MSG_VERBOSE( "[ trthit ] initialize() successful." );
68 return StatusCode::SUCCESS;
69}
70
71
72void iFatras::HitCreatorTRT::handle( const Incident& inc ) {
73 // check the incident type
74 if ( inc.type() == IncidentType::BeginEvent ){
75 // check if the hit collection already contains:
76 // (a) if yes ... try to retrieve it
78 if ( (evtStore()->retrieve(m_hitColl , m_collectionName)).isFailure() )
79 ATH_MSG_ERROR( "[ --- ] Unable to retrieve TRTUncompressedHitCollection " << m_collectionName);
80 // (a) if no ... try to create it
81 } else {
83 if ( (evtStore()->record(m_hitColl, m_collectionName, true)).isFailure() ) {
84 ATH_MSG_ERROR( "[ --- ] Unable to record TRTUncompressedHitCollection " << m_collectionName);
85 delete m_hitColl; m_hitColl=0;
86 }
87 }
88 }
89 return;
90}
91
92void iFatras::HitCreatorTRT::createSimHit(const ISF::ISFParticle& isp, const Trk::TrackParameters& pars, double time ) const
93{
94 // get surface and DetElement base
95 const Trk::Surface &hitSurface = pars.associatedSurface();
96 const Trk::TrkDetElementBase* detElementBase = hitSurface.associatedDetectorElement();
97 // the detector element cast -> needed
98 const InDetDD::TRT_BaseElement* hitTrtDetElement = dynamic_cast<const InDetDD::TRT_BaseElement*>((detElementBase));
99 //if cast fails, return 0
100 if ( !hitTrtDetElement ) return;
101 // checks for detector element and surface
102 if (hitTrtDetElement) {
103 // get the real identifier
105 // check conditions of the straw
106 if (m_useConditionsSvc && !m_trtStatusSummaryTool->get_status(hitId, Gaudi::Hive::currentContext()) ){
107 ATH_MSG_VERBOSE("[ trthit ] Straw is not active ( says ConditionsTool). Ignore. ");
108 return;
109 }
110 // create entry/exit point
111 const Amg::Vector3D& gpos1 = pars.position();
112 Amg::Vector3D gpos2 = gpos1 + pars.momentum().unit();
113 // get the rotation
114 const Amg::Transform3D& sTransform = hitSurface.transform();
115 // create the hep points
116 Amg::Vector3D lpoint1(sTransform.inverse() * gpos1);
117 Amg::Vector3D lpoint2(sTransform.inverse() * gpos2);
118
119 // new direction in 3D frame of cylinder
120 Amg::Vector3D direc((lpoint2 - lpoint1).unit());
121
122 // get line and circle constants
123 double k = (direc.y())/(direc.x());
124 double d = (lpoint2.x()*lpoint1.y() - lpoint1.x()*lpoint2.y())/(direc.x());
125 double R = hitSurface.bounds().r();
126
127 // and solve the qaudratic equation
128 Trk::RealQuadraticEquation pquad(1 + k*k, 2*k*d, d*d - R*R);
129 if (pquad.solutions != Trk::none){
130 double t1 = (pquad.first - lpoint1.x())/direc.x();
131 double t2 = (pquad.second - lpoint1.x())/direc.x();
132 // the solutions in the 3D frame of the cylinder : local coordination
133 Amg::Vector3D sol1raw( (lpoint1 + t1 * direc) );
134 Amg::Vector3D sol2raw( (lpoint1 + t2 * direc) );
135
136 ATH_MSG_VERBOSE("[ trthit ] Straw center : " << hitSurface.center());
137 ATH_MSG_VERBOSE("[ trthit ] Entry / exit : " << sol1raw << ", " << sol2raw );
138
140 const double mass = isp.mass();
141 const double mom2 = pars.momentum().mag2();
142 const float kineticEnergy = sqrt(mom2+mass*mass)-mass;
143 const float energyDepositInKeV = 0.; // only used for TRT hits directly created by photons
144
145 int barrel_endcap = 0;
146 int ispos = 0;
147 switch ( m_trtIdHelper->barrel_ec(hitId) ) {
148 case -2: barrel_endcap = 1; ispos = 1; break;
149 case -1: barrel_endcap = 0; ispos = 0; break;
150 case 1: barrel_endcap = 0; ispos = 1; break;
151 case 2: barrel_endcap = 1; ispos = 0; break;
152 default:
153 ATH_MSG_WARNING("[ trthit ] Problem estimating barrel_endcap and ispos" ); return;
154 }
155
156 const int ringwheel = m_trtIdHelper->layer_or_wheel(hitId);
157 const int phisector = m_trtIdHelper->phi_module(hitId);
158 const int layer = m_trtIdHelper->straw_layer(hitId);
159 const int istraw = m_trtIdHelper->straw(hitId);
160
161 const TRTHitIdHelper* hitid_helper = TRTHitIdHelper::GetHelper();
162 const int hitID = hitid_helper->buildHitId( barrel_endcap, ispos, ringwheel, phisector,layer,istraw);
163
164 ATH_MSG_VERBOSE("[ trthit ] Add a TRTUncompressedHit hit to the collection. ");
165 // fill into the HitCollection
166 HepMcParticleLink partLink(HepMC::uniqueID(isp), 0,
169 m_hitColl->Emplace( hitID,
170 partLink,
171 isp.pdgCode(),
172 (float) kineticEnergy, (float) energyDepositInKeV,
173 (float) sol1raw.x(), (float) sol1raw.y(), sol1raw.z(),
174 (float) sol2raw.x(), (float) sol2raw.y(), sol2raw.z(),
175 (float) time );
176 }
177
178 }
179}
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
AtlasHitsVector< TRTUncompressedHit > TRTUncompressedHitCollection
This is an Identifier helper class for the TRT subdetector.
The generic ISF particle definition,.
Definition ISFParticle.h:42
int pdgCode() const
PDG value.
double mass() const
mass of the particle
Virtual base class of TRT readout elements.
static const TRTHitIdHelper * GetHelper()
int buildHitId(const int, const int, const int, const int, const int, const int) const
virtual double r() const =0
Interface method for the maximal extension or the radius.
Abstract Base Class for tracking surfaces.
const TrkDetElementBase * associatedDetectorElement() const
return associated Detector Element
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
This is the base class for all tracking detector elements with read-out relevant information.
void handle(const Incident &inc)
handle for incident service
TRTUncompressedHitCollection * m_hitColl
the sim hit collection
ServiceHandle< IIncidentSvc > m_incidentSvc
const TRT_ID * m_trtIdHelper
TRT ID helper.
ServiceHandle< IAtRndmGenSvc > m_randomSvc
Pointer to the random number generator service.
StringProperty m_collectionName
name of the collection on storegate
ToolHandle< ITRT_StrawStatusSummaryTool > m_trtStatusSummaryTool
Handle to TRT conditions service.
CLHEP::HepRandomEngine * m_randomEngine
Random Engine.
StringProperty m_trtIdHelperName
where to find the SCT helper
StringProperty m_randomEngineName
Name of the random number stream.
StatusCode initialize()
AlgTool initailize method.
HitCreatorTRT(const std::string &, const std::string &, const IInterface *)
Constructor.
void createSimHit(const ISF::ISFParticle &isp, const Trk::TrackParameters &, double) const
Record the hit.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
int uniqueID(const T &p)
ParametersBase< TrackParametersDim, Charged > TrackParameters