ATLAS Offline Software
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"
10 #include "StoreGate/StoreGateSvc.h"
11 // ISF
13 #include "ISF_Event/ISFParticle.h"
14 // Tracking
16 #include "TrkSurfaces/Surface.h"
24 // InDet
25 #include "InDetIdentifier/TRT_ID.h"
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:
51  m_randomEngine = m_randomSvc->GetEngine(m_randomEngineName);
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 
72 void 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
77  if ( evtStore()->contains<TRTUncompressedHitCollection>(m_collectionName) ){
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 {
82  m_hitColl = new TRTUncompressedHitCollection( m_collectionName);
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 
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
104  Identifier hitId = hitSurface.associatedDetectorElementIdentifier();
105  // check conditions of the straw
106  if (m_useConditionsSvc && !m_trtStatusSummaryTool->get_status(hitId) ){
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::barcode(isp), 0,
168  HepMcParticleLink::IS_BARCODE); // FIXME barcode-based
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
TrkDetElementBase.h
Trk::Surface::associatedDetectorElement
const TrkDetElementBase * associatedDetectorElement() const
return associated Detector Element
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Surface.h
iFatras::HitCreatorTRT::HitCreatorTRT
HitCreatorTRT(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: HitCreatorTRT.cxx:36
Trk::RealQuadraticEquation::second
double second
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:55
hist_file_dump.d
d
Definition: hist_file_dump.py:137
IParticleBroker.h
Trk::Surface::associatedDetectorElementIdentifier
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
iFatras::HitCreatorTRT::handle
void handle(const Incident &inc)
handle for incident service
Definition: HitCreatorTRT.cxx:72
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
ISF::ISFParticle
Definition: ISFParticle.h:42
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
Trk::none
@ none
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:21
ISF::ISFParticle::pdgCode
int pdgCode() const
PDG value.
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::RealQuadraticEquation::solutions
RQESolutionType solutions
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:56
Trk::Surface::center
const Amg::Vector3D & center() const
Returns the center position of the Surface.
ParamDefs.h
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
TRTHitIdHelper.h
RealQuadraticEquation.h
SurfaceBounds.h
ISFParticle.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DefinedParameter.h
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
HitCreatorTRT.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::RealQuadraticEquation
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:52
TRTHitIdHelper::GetHelper
static const TRTHitIdHelper * GetHelper()
Definition: TRTHitIdHelper.cxx:13
Trk::ParametersBase
Definition: ParametersBase.h:55
ParticleHypothesis.h
TRT_BaseElement.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Trk::Surface::bounds
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
RIO_OnTrack.h
TRTHitIdHelper::buildHitId
int buildHitId(const int, const int, const int, const int, const int, const int) const
Definition: TRTHitIdHelper.cxx:72
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
LocalParameters.h
Trk::RealQuadraticEquation::first
double first
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:54
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
TRTUncompressedHit.h
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
iFatras::HitCreatorTRT::initialize
StatusCode initialize()
AlgTool initailize method.
Definition: HitCreatorTRT.cxx:46
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:20
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
StoreGateSvc.h
TRTHitIdHelper
Definition: TRTHitIdHelper.h:25
iFatras::HitCreatorTRT::createSimHit
void createSimHit(const ISF::ISFParticle &isp, const Trk::TrackParameters &, double) const
Record the hit.
Definition: HitCreatorTRT.cxx:92
fitman.k
k
Definition: fitman.py:528
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
ISF::ISFParticle::mass
double mass() const
mass of the particle
Trk::SurfaceBounds::r
virtual double r() const =0
Interface method for the maximal extension or the radius.
TRTUncompressedHitCollection
AtlasHitsVector< TRTUncompressedHit > TRTUncompressedHitCollection
Definition: TRTUncompressedHitCollection.h:16