42 const float FPGATrackSim_PT_TRUTHMIN = 400.;
43 const float FPGATrackSim_Z_TRUTHMIN = 2300.;
47 base_class(algname, name, ifc)
76 return StatusCode::SUCCESS;
81 return StatusCode::SUCCESS;
95 event_info.
setLB(eventInfo->lumiBlock());
96 event_info.
setBCID(eventInfo->bcid());
111 std::vector <FPGATrackSimCluster> clusters;
118 std::vector <FPGATrackSimTruthTrack> truth;
123 std::vector <FPGATrackSimOfflineTrack>
offline;
132 return StatusCode::SUCCESS;
139 ATH_MSG_DEBUG(
"read Offline tracks, size= " << offlineTracksHandle->size());
145 tmpOfflineTrack.
setQOverPt(trackParticle->pt() > 0 ? trackParticle->charge() / trackParticle->pt() : 0);
146 tmpOfflineTrack.
setEta(trackParticle->eta());
147 tmpOfflineTrack.
setPhi(trackParticle->phi());
148 tmpOfflineTrack.
setD0(trackParticle->d0());
149 tmpOfflineTrack.
setZ0(trackParticle->z0());
151 const Trk::TrackStates* trackStates = trackParticle->track()->trackStateOnSurfaces();
152 if (trackStates ==
nullptr) {
154 return StatusCode::FAILURE;
157 if (tsos ==
nullptr)
continue;
160 if (tsos->trackParameters() !=
nullptr &&
161 tsos->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr &&
162 tsos->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0
178 else if (
m_sctId->is_sct(hitId)) {
186 tmpOfflineHit.
setLocY(-99999.9);
188 tmpOfflineTrack.
addHit(tmpOfflineHit);
192 offline.push_back(tmpOfflineTrack);
196 return StatusCode::SUCCESS;
206 const EventContext& eventContext)
const
209 unsigned int hitIndex = 0u;
214 return StatusCode::SUCCESS;
222 unsigned int& hitIndex,
223 const EventContext& eventContext)
const {
231 if (pixel_rdoCollection ==
nullptr) {
continue; }
244 hitIndexMap[rdoId] = hitIndex;
249 hitIndexMap[tmpId] = hitIndex;
255 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
256 if (nCells > 1 && iter == pixelSDOHandle->end()) {
258 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
263 if (iter != pixelSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
276 int barrel_ec =
m_pixelId->barrel_ec(rdoId);
279 else if (barrel_ec == 2)
281 else if (barrel_ec == -2)
296 tmpSGhit.
setToT(pixelRawData->getToT());
305 tmpSGhit.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
306 tmpSGhit.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
309 tmpSGhit.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
320 eventHeader->
addHit(tmpSGhit);
324 return StatusCode::SUCCESS;
331 unsigned int& hitIndex,
332 const EventContext& eventContext)
const {
334 constexpr int MaxChannelinStripRow = 128;
340 if (SCT_Collection ==
nullptr) {
continue; }
342 std::map<int, bool> firedStrips;
343 std::map<int, const SCT_RDORawData*> firedStripsToRDO;
349 const Identifier rdoId = sctRawData->identify();
350 const int baseLineStrip{
m_sctId->strip(rdoId)};
351 for(
int i = 0; i < sctRawData->getGroupSize(); i++) {
352 firedStrips[baseLineStrip+ i] =
true;
353 firedStripsToRDO[baseLineStrip + i] = sctRawData;
359 std::map<int, int> stripEncodingForITK;
360 std::map<int, const SCT_RDORawData* > stripEncodingForITKToRDO;
361 for(
const auto& [stripID, fired]: firedStrips)
369 std::bitset<3> hitMap;
373 int currChipID = stripID / MaxChannelinStripRow;
375 int maxStripIDForCurrChip = (currChipID + 1) * MaxChannelinStripRow;
377 for(
int i = 0; i < 3; i++)
380 if((stripID + 1 + i) >= maxStripIDForCurrChip)
continue;
382 if(firedStrips.find(stripID + 1 + i) != firedStrips.end())
384 if(firedStrips.at(stripID + 1 + i))
387 firedStrips[stripID + 1 + i] =
false;
397 stripEncodingForITK[stripID] = (int)(hitMap.to_ulong());
398 stripEncodingForITKToRDO[stripID] = firedStripsToRDO[stripID];
402 for(
const auto& [stripID, fired]: firedStrips)
412 std::pair<Amg::Vector3D, Amg::Vector3D> endsOfStrip = sielement->
endsOfStrip(localPos);
414 hitIndexMap[rdoId] = hitIndex;
421 InDetSimDataCollection::const_iterator iter(stripSDOHandle->find(rdoId));
423 if (iter != stripSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
435 int barrel_ec =
m_sctId->barrel_ec(rdoId);
438 else if (barrel_ec == 2)
440 else if (barrel_ec == -2)
460 tmpSGhit.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
461 tmpSGhit.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
465 if(stripEncodingForITK.find(stripID) != stripEncodingForITK.end())
469 int chipID = stripID / MaxChannelinStripRow;
470 int ITkStripID = stripID % MaxChannelinStripRow;
476 int offset =
m_sctId->eta_module(rdoId) % 2;
477 if(
m_sctId->barrel_ec(rdoId) == 0) offset = (std::abs(
m_sctId->eta_module(rdoId)) - 1) % 2;
479 ITkStripID += offset * MaxChannelinStripRow;
487 tmpSGhit.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
489 tmpSGhit.
setX(0.5 * (endsOfStrip.first.x() + endsOfStrip.second.x()));
490 tmpSGhit.
setY(0.5 * (endsOfStrip.first.y() + endsOfStrip.second.y()));
491 tmpSGhit.
setZ(0.5 * (endsOfStrip.first.z() + endsOfStrip.second.z()));
501 eventHeader->
addHit(tmpSGhit);
506 return StatusCode::SUCCESS;
512 unsigned int pixelClusterIndex = 0;
516 for (
const InDet::SiClusterCollection* pixelClusterCollection : *pixelClusterContainerHandle) {
517 if (pixelClusterCollection ==
nullptr) {
527 for (
const Identifier& rdoId : cluster->rdoList()) {
533 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
535 if (nCells > 1 && iter == pixelSDOHandle->end()) {
537 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
545 pixelClusterIndexMap[theId] = pixelClusterIndex;
550 return StatusCode::SUCCESS;
563 for (
const InDet::SiClusterCollection* pixelClusterCollection : *pixelClusterContainerHandler) {
564 if (pixelClusterCollection ==
nullptr) {
568 const int size = pixelClusterCollection->size();
576 for (
const Identifier& rdoId : cluster->rdoList()) {
581 InDetSimDataCollection::const_iterator iter(pixelSDOHandle->find(rdoId));
583 if (nCells > 1 && iter == pixelSDOHandle->end()) {
585 for (
int ii = 0; ii < nCells && iter == pixelSDOHandle->end(); ++ii) {
590 if (iter != pixelSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
606 clusterEquiv.
setX(globalPos.x());
607 clusterEquiv.
setY(globalPos.y());
608 clusterEquiv.
setZ(globalPos.z());
613 int barrel_ec =
m_pixelId->barrel_ec(theID);
616 else if (barrel_ec == 2)
618 else if (barrel_ec == -2)
629 clusterEquiv.
setPhiWidth(cluster->width().colRow()[1]);
630 clusterEquiv.
setEtaWidth(cluster->width().colRow()[0]);
638 clusterEquiv.
setEventIndex(std::numeric_limits<long>::max());
639 clusterEquiv.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
640 clusterEquiv.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
643 clusterEquiv.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
646 clusters.push_back(clusterOut);
658 if (SCT_Collection ==
nullptr) {
continue; }
660 const Identifier rdoId = sctRawData->identify();
671 InDetSimDataCollection::const_iterator iter(stripSDOHandle->find(rdoId));
673 if (iter != stripSDOHandle->end()) { bestTruthLink =
getTruthInformation(iter, parentMask); }
688 int barrel_ec =
m_sctId->barrel_ec(rdoId);
691 else if (barrel_ec == 2)
693 else if (barrel_ec == -2)
705 clusterEquiv.
setPhiWidth(sctRawData->getGroupSize());
713 clusterEquiv.
setEventIndex(std::numeric_limits<long>::max());
714 clusterEquiv.
setBarcode(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
715 clusterEquiv.
setUniqueID(std::numeric_limits<HepMcParticleLink::barcode_type>::max());
718 clusterEquiv.
setBarcodePt(
static_cast<unsigned long>(std::ceil(bestParent ? bestParent->momentum().perp() : 0.)));
721 clusters.push_back(clusterOut);
726 return StatusCode::SUCCESS;
733 ATH_MSG_DEBUG(
"Dump truth tracks, size " << simTracksHandle->size());
736 for (
unsigned int ievt = 0; ievt < simTracksHandle->size(); ++ievt) {
739 HepGeom::Point3D<double> primaryVtx(0., 0., 0.);
744 primaryVtx.set(spv->position().x(),
746 spv->position().z());
747 ATH_MSG_DEBUG(
"using signal process vertex for eventIndex " << ievt <<
":"
748 << primaryVtx.x() <<
"\t" << primaryVtx.y() <<
"\t" << primaryVtx.z());
750 for (
const auto& particle: *genEvent) {
751 const int pdgcode = particle->pdg_id();
753 if (particle->production_vertex() ==
nullptr) {
757 if (std::abs(
charge) < 0.5) {
764 const Amg::Vector3D momentum(particle->momentum().px(), particle->momentum().py(), particle->momentum().pz());
765 const Amg::Vector3D position(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
777 const double track_truth_d0 = tP ? tP->parameters()[
Trk::d0] : 999.;
778 const double track_truth_phi = tP ? tP->parameters()[
Trk::phi] : 999.;
779 const double track_truth_p = (tP && fabs(tP->parameters()[
Trk::qOverP]) > 1.e-8) ?
780 tP->charge() / tP->parameters()[
Trk::qOverP] : 10E7;
781 const double track_truth_x0 = tP ? tP->position().x() : 999.;
782 const double track_truth_y0 = tP ? tP->position().y() : 999.;
783 const double track_truth_z0 = tP ? tP->parameters()[
Trk::z0] : 999.;
784 const double track_truth_q = tP ? tP->charge() : 0.;
785 const double track_truth_sinphi = tP ? std::sin(tP->parameters()[
Trk::phi]) : -1.;
786 const double track_truth_cosphi = tP ? std::cos(tP->parameters()[
Trk::phi]) : -1.;
787 const double track_truth_sintheta = tP ? std::sin(tP->parameters()[
Trk::theta]) : -1.;
788 const double track_truth_costheta = tP ? std::cos(tP->parameters()[
Trk::theta]) : -1.;
789 double truth_d0corr = track_truth_d0 - (primaryVtx.y() * cos(track_truth_phi) - primaryVtx.x() * sin(track_truth_phi));
790 double truth_zvertex = 0.;
791 const HepGeom::Point3D<double> startVertex(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
793 bool isPrimary =
true;
794 if (std::abs(truth_d0corr) > 2.) { isPrimary =
false; }
798 if (isPrimary && particle->production_vertex()) {
799 const HepGeom::Point3D<double> startVertex(particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z());
800 if (std::abs(startVertex.z() - truth_zvertex) > 100.) { isPrimary =
false; }
801 if (particle->end_vertex()) {
802 HepGeom::Point3D<double> endVertex(particle->end_vertex()->position().x(), particle->end_vertex()->position().y(), particle->end_vertex()->position().z());
803 if (endVertex.perp() < FPGATrackSim_PT_TRUTHMIN && std::abs(endVertex.z()) < FPGATrackSim_Z_TRUTHMIN) { isPrimary =
false; }
813 tmpSGTrack.
setVtxX(track_truth_x0);
814 tmpSGTrack.
setVtxY(track_truth_y0);
815 tmpSGTrack.
setVtxZ(track_truth_z0);
816 tmpSGTrack.
setD0(track_truth_d0);
817 tmpSGTrack.
setZ0(track_truth_z0);
818 tmpSGTrack.
setQ(track_truth_q);
819 tmpSGTrack.
setPX(track_truth_p * (track_truth_cosphi * track_truth_sintheta));
820 tmpSGTrack.
setPY(track_truth_p * (track_truth_sinphi * track_truth_sintheta));
821 tmpSGTrack.
setPZ(track_truth_p * track_truth_costheta);
823 tmpSGTrack.
setStatus(particle->status());
829 truth.push_back(tmpSGTrack);
834 return StatusCode::SUCCESS;
842 const std::vector<InDetSimData::Deposit>& deposits(sdo.
getdeposits());
843 float bestPt{-999.f};
848 if (!particleLink.
isValid()) {
continue; }
849 const float genEta = particleLink->momentum().pseudoRapidity();
850 const float genPt = particleLink->momentum().perp();
856 if (std::fabs(genEta) >
m_maxEta) {
continue; }
858 if (bestPt < genPt) {
860 bestTruthLink = &particleLink;
865 return bestTruthLink;
#define ATH_CHECK
Evaluate an expression and check for errors.
double charge(const T &p)
: FPGATrackSim-specific class to represent an hit in the detector.
ATLAS-specific HepMC functions.
size_t size() const
Number of registered mappings.
void setClusterEquiv(const FPGATrackSimHit &input)
void setaverageInteractionsPerCrossing(const int &val)
void setBCID(const int &val)
void setLB(const int &val)
void setRunNumber(const unsigned long &val)
void setlevel1TriggerType(const unsigned int &val)
void setactualInteractionsPerCrossing(const int &val)
void setEventNumber(const unsigned long &val)
void setextendedLevel1ID(const unsigned int &val)
void setPhiModule(unsigned v)
void setIdentifierHash(unsigned v)
void setEtaIndex(unsigned v)
void setEventIndex(long v)
void setPhiIndex(unsigned v)
void setStripChipIDForITk(int v)
long getEventIndex() const
void setHitType(HitType type)
float getBarcodePt() const
void setPhiCoord(float v)
void setIdentifier(unsigned int v)
void setBarcode(const HepMcParticleLink::barcode_type &v)
void setisValidForITkHit(bool v)
void setRdoIdentifier(Identifier::value_type v)
void setParentageMask(unsigned long v)
void setBarcodePt(float v)
HepMcParticleLink::barcode_type getBarcode() const
void setLayerDisk(unsigned v)
void setStripHitMapForITk(int v)
void setStripRowIDForITk(int v)
void setEtaCoord(float v)
void setTruth(const FPGATrackSimMultiTruth &v)
void setEtaWidth(unsigned v)
void setPhiWidth(unsigned v)
void setUniqueID(const HepMcParticleLink::barcode_type &v)
void setDetectorZone(DetectorZone detZone)
void setDetType(SiliconTech detType)
void maximize(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
std::pair< unsigned long, unsigned long > Barcode
void setClusterID(int clus)
void setIsBarrel(bool is)
void setTrackNumber(int track)
void setQOverPt(double v)
void addHit(const FPGATrackSimOfflineHit &s)
void addOfflineCluster(const FPGATrackSimCluster &c) const
size_t nTruthTracks() const
size_t nOfflineClusters() const
void addOfflineTrack(const FPGATrackSimOfflineTrack &t) const
void addTruthTrack(const FPGATrackSimTruthTrack &t) const
size_t nOfflineTracks() const
void setUniqueID(const HepMcParticleLink::barcode_type &v)
void setBarcode(const HepMcParticleLink::barcode_type &v)
void setEventIndex(int v)
a link optimized in size for a GenParticle in a McEventCollection
int id() const
Return the id of the target particle.
bool isValid() const
Validity check.
HepMC::ConstGenParticlePtr cptr() const
Dereference.
index_type eventIndex() const
Return the event number of the referenced GenEvent.
int barcode() const
Return the barcode of the target particle.
value_type get_compact() const
Get the compact id.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
virtual SiCellId connectedCell(const SiReadoutCellId &readoutId, int number) const =0
readout id -> id of connected diodes.
virtual SiLocalPosition localPositionOfCell(const SiCellId &cellId) const =0
readout or diode id -> position.
Identifier for the strip or pixel cell.
Base class for the detector design classes for Pixel and SCT.
Class to hold geometrical description of a silicon detector element.
virtual SiCellId cellIdFromIdentifier(const Identifier &identifier) const override final
SiCellId from Identifier.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
std::pair< Amg::Vector3D, Amg::Vector3D > endsOfStrip(const Amg::Vector2D &position) const
Special method for SCT to retrieve the two ends of a "strip" Returned coordinates are in global frame...
virtual Identifier identifierFromCellId(const SiCellId &cellId) const override final
Identifier <-> SiCellId (ie strip number or pixel eta_index,phi_index) Identifier from SiCellId (ie s...
Class to represent a position in the natural frame of a silicon sensor, for Pixel and SCT For Pixel: ...
double xPhi() const
position along phi direction:
double xEta() const
position along eta direction:
Identifier for the strip or pixel readout cell.
SiCellId connectedCell(const SiCellId cellId, int number) const
Get the cell ids sharing the readout for this cell.
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
int numberOfConnectedCells(const SiCellId cellId) const
Test if readout cell has more than one diode associated with it.
HepGeom::Point3D< double > globalPosition(const HepGeom::Point3D< double > &localPos) const
transform a reconstruction local position into a global position (inline):
virtual Identifier identify() const override final
identifier of this detector element (inline)
Amg::Vector2D rawLocalPositionOfCell(const SiCellId &cellId) const
Returns position (center) of cell.
virtual Identifier identify() const override final
std::pair< HepMcParticleLink, float > Deposit
const std::vector< Deposit > & getdeposits() const
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Class describing the Line to which the Perigee refers to.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Identifier identify() const
return the identifier -extends MeasurementBase
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
HepMC3::GenEvent GenEvent
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
double charge(const T &p)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
DataVector< const Trk::TrackStateOnSurface > TrackStates
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
TrackParticle_v1 TrackParticle
Reference the current persistent version: