ATLAS Offline Software
EntryLayerTool.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 include
6 #include "EntryLayerTool.h"
7 
9 
10 // ISF includes
11 #include "ISF_Event/ISFParticle.h"
13 
14 // ISF interfaces
16 
18 ISF::EntryLayerTool::EntryLayerTool(const std::string& t, const std::string& n, const IInterface* p) :
19  base_class(t,n,p),
20  m_geoIDSvc("GeoIDSvc",n),
21  m_geoIDSvcQuick(0),
22  m_particleFilterHandle(),
23  m_particleFilter(),
24  m_numParticleFilters(0),
25  m_collection(),
26  m_SGName(),
27  m_volumeName()
28 {
29  // geometry identification service
30  declareProperty( "GeoIDSvc",
31  m_geoIDSvc,
32  "AthenaService used to indentify sub-detector by (x,y,z) coordintes.");
33 
34  // particle filters
35  declareProperty( "ParticleFilters",
37  "ISF Particle filters, defining whether a particle will be stored or not.");
38 
39  // storegate collection names
40  declareProperty( "CaloEntryLayer",
41  m_SGName[ISF::fAtlasCaloEntry] = "CaloEntryLayer",
42  "Name of CaloEntryLayer collection on Storegate");
43  declareProperty( "MuonEntryLayer",
44  m_SGName[ISF::fAtlasMuonEntry] = "MuonEntryLayer",
45  "Name of MuonEntryLayer collection on Storegate");
46  declareProperty( "MuonExitLayer",
47  m_SGName[ISF::fAtlasMuonExit] = "MuonExitLayer",
48  "Name of MuonExitLayer collection on Storegate");
49 
50  // volumeNames for TrackRecords
51  declareProperty( "CaloEntryVolumeString",
52  m_volumeName[ISF::fAtlasCaloEntry] = "IDET::IDET",
53  "VolumeName in TrackRecords in CaloEntryLayer");
54  declareProperty( "MuonEntryVolumeString",
55  m_volumeName[ISF::fAtlasMuonEntry] = "CALO::CALO",
56  "VolumeName in TrackRecords in MuonEntryLayer");
57  declareProperty( "MuonExitVolumeString",
58  m_volumeName[ISF::fAtlasMuonExit] = "MUONQ02::MUONQ02",
59  "VolumeName in TrackRecords in MuonExitLayer");
60 }
61 
62 
65 {
66  ATH_MSG_INFO("initialize() ...");
67 
68  // retrieve the GeoIDSvc
69  if ( m_geoIDSvc.retrieve().isFailure() ){
70  ATH_MSG_FATAL( "Could not retrieve GeoID service. Abort.");
71  return StatusCode::FAILURE;
72  }
73  // store a quick-access pointer to the c++ class directly
74  m_geoIDSvcQuick = &(*m_geoIDSvc);
75 
76 
77  // retrieve the ParticleFilters
78  if ( m_particleFilterHandle.retrieve().isFailure() ){
79  ATH_MSG_FATAL( "Could not retrieve ParticleFilters. Abort.");
80  return StatusCode::FAILURE;
81  }
82  // store a quick-access pointer to the c++ classes directly
83  m_numParticleFilters = m_particleFilterHandle.size();
84  m_particleFilter = new ISF::IParticleFilter*[ m_numParticleFilters ];
85  for ( size_t curFilter = 0; curFilter<m_numParticleFilters; curFilter++) {
86  // convert ToolHandle to standard c++ class pointer
87  m_particleFilter[curFilter] = &(*m_particleFilterHandle[curFilter]);
88  }
89 
90  ATH_MSG_INFO("initialize() successful");
91  return StatusCode::SUCCESS;
92 }
93 
94 
96 
97  // initialize storegate collections at BeginEvent incident
98  for ( int entryLayer=ISF::fFirstAtlasEntryLayer;
99  entryLayer<ISF::fNumAtlasEntryLayers;
100  entryLayer++) {
101  m_collection[entryLayer] = setupSGCollection( m_SGName[entryLayer] );
102  }
103 
104  return;
105 }
106 
107 
110  bool pass = true;
111  for ( size_t curFilter=0; pass && (curFilter<m_numParticleFilters); curFilter++) {
112  // check current filter
113  pass = m_particleFilter[curFilter]->passFilter( particle);
114  }
115 
116  return pass;
117 }
118 
119 
123  // the return value
125 
126  const Amg::Vector3D &pos = particle.position();
127 
128  // check if particle on ID and/or Calo surface
129  bool onIDSurface = (m_geoIDSvcQuick->inside( pos, AtlasDetDescr::fAtlasID) == ISF::fSurface);
130  bool onCaloSurface = (m_geoIDSvcQuick->inside( pos, AtlasDetDescr::fAtlasCalo) == ISF::fSurface);
131 
132  // on CaloEntry layer ?
133  if ( onIDSurface && onCaloSurface ) {
134  layerHit = ISF::fAtlasCaloEntry;
135  }
136 
137  // no surface hit yet -> test MS volume surface hit
138  else {
139  // check if particle on MS surface
140  bool onMSSurface = (m_geoIDSvcQuick->inside( pos, AtlasDetDescr::fAtlasMS) == ISF::fSurface);
141 
142  // on MuonEntry layer ?
143  if (onCaloSurface && onMSSurface) {
144  layerHit = ISF::fAtlasMuonEntry;
145  }
146  // on MuonExit layer ?
147  else if (onMSSurface) {
148  layerHit = ISF::fAtlasMuonExit;
149  }
150  }
151  return layerHit;
152 }
153 
154 
157 {
158  // (1.) check whether the particle actually passes all the filters
159  // -> rather fast usually
160  if ( !passesFilters(particle) ) {
161  // return if not passed
162  return ISF::fUnsetEntryLayer;
163  }
164 
165  // (2.) check whether the particle lies on any entry surface
166  // -> this goes second because computation intensive routines
167  // are used for this
168  if ( layerHit == ISF::fUnsetEntryLayer) {
169  layerHit = identifyEntryLayer( particle);
170  }
171 
172  // (3.) if particle is on a boundary surface
173  // -> add it to TrackRecordCollection
174  if ( layerHit != ISF::fUnsetEntryLayer) {
175  ATH_MSG_VERBOSE( "Particle >>" << particle << "<< hit boundary surface, "
176  "adding it to '" << m_SGName[layerHit] << "' TrackRecord collection");
177 
178  const Amg::Vector3D &pos = particle.position();
179  const Amg::Vector3D &mom = particle.momentum();
180  CLHEP::Hep3Vector hepPos( pos.x(), pos.y(), pos.z() ); // not optimal, but required by TrackRecord
181  CLHEP::Hep3Vector hepMom( mom.x(), mom.y(), mom.z() ); // not optimal, but required by TrackRecord
182 
183  double mass = particle.mass();
184  double energy = sqrt(mass*mass + mom.mag2());
185 
186  // Use barcode of generation zero particle from truth binding if possible (reproduces legacy AtlasG4 behaviour).
187  // Use barcode assigend to ISFParticle only if no generation zero particle is present.
188  auto truthBinding = particle.getTruthBinding();
189  auto generationZeroGenParticle = truthBinding ? truthBinding->getGenerationZeroGenParticle() : nullptr;
190  const int barcode = generationZeroGenParticle ? HepMC::barcode(generationZeroGenParticle) : HepMC::barcode(particle); // FIXME barcode-based
191  const int id = generationZeroGenParticle ? HepMC::uniqueID(generationZeroGenParticle) : particle.id();
192  const int status = generationZeroGenParticle ? generationZeroGenParticle->status() : particle.status();
193 
194  m_collection[layerHit]->Emplace(particle.pdgCode(),
195  status,
196  energy,
197  hepMom,
198  hepPos,
199  particle.timeStamp(),
200  barcode, // FIXME barcode-based
201  id,
202  m_volumeName[layerHit] );
203  }
204 
205  return layerHit;
206 }
207 
210 {
211  m_collection[layer]=collection; // Dummy implementation.
212  return StatusCode::SUCCESS;
213 }
214 
215 
216 
219 {
220  TrackRecordCollection *collection = 0;
221 
222  // check if storegate already contains the collection
223  // (a) if yes ... try to retrieve it
224  if ( evtStore()->contains<TrackRecordCollection>(collectionName) ){
225  if ( (evtStore()->retrieve( collection, collectionName)).isFailure() )
226  ATH_MSG_ERROR( "[ --- ] Unable to retrieve TrackRecordCollection " << collectionName);
227  // (b) if no ... try to create it
228  } else {
229  collection = new TrackRecordCollection( collectionName);
230  if ( (evtStore()->record( collection, collectionName, true)).isFailure() ) {
231  ATH_MSG_ERROR( "[ --- ] Unable to record SiHitCollection " << collectionName);
232  delete collection;
233  collection=0;
234  }
235  }
236 
237  return collection;
238 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ISF::fAtlasMuonEntry
@ fAtlasMuonEntry
Definition: EntryLayer.h:38
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ISF::EntryLayerTool::registerParticle
virtual ISF::EntryLayer registerParticle(const ISF::ISFParticle &particle, ISF::EntryLayer entryLayer) override final
Add the given particle to the corresponding Entry/Exit layer if applicable.
Definition: EntryLayerTool.cxx:156
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
ISF::EntryLayerTool::passesFilters
virtual bool passesFilters(const ISFParticle &particle) override final
Check if given particle passes the EntryLayer filters.
Definition: EntryLayerTool.cxx:109
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ISF::EntryLayerTool::m_SGName
std::string m_SGName[ISF::fNumAtlasEntryLayers]
Definition: EntryLayerTool.h:83
ISF::EntryLayerTool::m_particleFilterHandle
ParticleFilterArray m_particleFilterHandle
Array of filters to decide whether a particle is added to the Entry/Exit layer.
Definition: EntryLayerTool.h:77
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ISF::fAtlasMuonExit
@ fAtlasMuonExit
Definition: EntryLayer.h:39
ISF::EntryLayerTool::initialize
virtual StatusCode initialize() override final
Athena algtool's Hooks.
Definition: EntryLayerTool.cxx:64
AtlasHitsVector
Definition: AtlasHitsVector.h:33
ISF::ISFParticle
Definition: ISFParticle.h:42
TrackRecordCollection
AtlasHitsVector< TrackRecord > TrackRecordCollection
Definition: TrackRecordCollection.h:12
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
ISF::fSurface
@ fSurface
Definition: IGeoIDSvc.h:24
ISF::EntryLayerTool::identifyEntryLayer
virtual ISF::EntryLayer identifyEntryLayer(const ISFParticle &particle) override final
Identify the corresponding entry layer for the given particle (may return ISF::fUnsetEntryLayer if pa...
Definition: EntryLayerTool.cxx:122
ISF::EntryLayerTool::setupEvent
virtual void setupEvent() override final
Definition: EntryLayerTool.cxx:95
ISFParticle.h
ISF::fNumAtlasEntryLayers
@ fNumAtlasEntryLayers
Definition: EntryLayer.h:41
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
ISF::fUnsetEntryLayer
@ fUnsetEntryLayer
Definition: EntryLayer.h:33
EntryLayerTool.h
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
AtlasDetDescr::fAtlasMS
@ fAtlasMS
Definition: AtlasRegion.h:36
beamspotman.n
n
Definition: beamspotman.py:731
IParticleFilter.h
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
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:113
ISF::fFirstAtlasEntryLayer
@ fFirstAtlasEntryLayer
Definition: EntryLayer.h:35
ISF::EntryLayerTool::m_geoIDSvc
ServiceHandle< ISF::IGeoIDSvc > m_geoIDSvc
GeoIDSvc will be used to determine the entry layer surface, the particle is on.
Definition: EntryLayerTool.h:73
IGeoIDSvc.h
MagicNumbers.h
AtlasDetDescr::fAtlasID
@ fAtlasID
Definition: AtlasRegion.h:33
ISF::EntryLayerTool::EntryLayerTool
EntryLayerTool(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: EntryLayerTool.cxx:18
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ISF::EntryLayer
EntryLayer
Definition: EntryLayer.h:31
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ISF::EntryLayerTool::setupSGCollection
TrackRecordCollection * setupSGCollection(const std::string &name)
used to setup a TrackRecordCollection on storegate
Definition: EntryLayerTool.cxx:218
ISF::EntryLayerTool::registerTrackRecordCollection
virtual StatusCode registerTrackRecordCollection(TrackRecordCollection *collection, EntryLayer layer) override final
Register the TrackRecordCollection pointer for a layer.
Definition: EntryLayerTool.cxx:209
AtlasDetDescr::fAtlasCalo
@ fAtlasCalo
Definition: AtlasRegion.h:35
ISF::fAtlasCaloEntry
@ fAtlasCaloEntry
Definition: EntryLayer.h:37
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
merge.status
status
Definition: merge.py:17
ISF::EntryLayerTool::m_volumeName
std::string m_volumeName[ISF::fNumAtlasEntryLayers]
Definition: EntryLayerTool.h:84
ISF::IParticleFilter
Definition: IParticleFilter.h:28