10#include "CaloGeoHelpers/CaloSampling.h"
18#include "GaudiKernel/PhysicalConstants.h"
26 constexpr double inv_c = 1./Gaudi::Units::c_light;
31 ISvcLocator* pSvcLocator)
46 return StatusCode::SUCCESS;
69 return StatusCode::SUCCESS;
88 throw std::runtime_error(
"Could not load the " + key.key() +
" segment container");
90 unsigned int ncbCounter = 0;
91 for (
const Trk::Segment *ncbSegment : *ncbSegmentHandle) {
97 ATH_MSG_WARNING(
"Found a muon segment in the container which pretends not to be a muon segment..");
102 if (stIndex != Muon::MuonStationIndex::StIndex::EI) {
110 constexpr int highestSegQual = 3;
123 if (!caloClusterContainerReadHandle.
isPresent()){
124 throw std::runtime_error(
"Failed to load the calorimeter cluster container");
128 constexpr std::array<CaloSampling::CaloSample, 24> caloLayers{CaloSampling::CaloSample::PreSamplerB,
129 CaloSampling::CaloSample::EMB1, CaloSampling::CaloSample::EMB2, CaloSampling::CaloSample::EMB3,
130 CaloSampling::CaloSample::PreSamplerE,
131 CaloSampling::CaloSample::EME1, CaloSampling::CaloSample::EME2, CaloSampling::CaloSample::EME3,
132 CaloSampling::CaloSample::FCAL0,
134 CaloSampling::CaloSample::HEC0, CaloSampling::CaloSample::HEC1, CaloSampling::CaloSample::HEC2, CaloSampling::CaloSample::HEC3,
136 CaloSampling::CaloSample::TileBar0, CaloSampling::CaloSample::TileBar1, CaloSampling::CaloSample::TileBar2,
137 CaloSampling::CaloSample::TileGap1, CaloSampling::CaloSample::TileGap2, CaloSampling::CaloSample::TileGap3,
138 CaloSampling::CaloSample::TileExt0, CaloSampling::CaloSample::TileExt1, CaloSampling::CaloSample::TileExt2, CaloSampling::CaloSample::FCAL1,
139 CaloSampling::CaloSample::FCAL2};
141 unsigned int caloClusterCounter = 0;
142 for (
const xAOD::CaloCluster* thisCaloCluster : *caloClusterContainerReadHandle) {
143 ++caloClusterCounter;
145 for (
auto lay : caloLayers){
146 eClus +=thisCaloCluster->eSample(lay);
158 rClus = rClus / std::cosh(thisCaloCluster->eta());
166 const double phiClus = thisCaloCluster->phi();
169 std::vector<int> matchedSegmentsPerCluster(cache.
m_indexSeg.size(), 0);
172 for (
unsigned int j = 0; j < cache.
m_indexSeg.size(); j++) {
176 const double phiSeg = globalPos.phi();
182 <<
"Segment: "<<
Amg::toString(globalPos)<<
", phi: "<<globalPos.phi()
183 <<
" --- Cluster: "<<phiClus);
187 const double rSeg = globalPos.perp();
191 <<
"Segment: "<<
Amg::toString(globalPos)<<
", phi: "<<globalPos.perp()
192 <<
" --- Cluster: "<<rClus);
195 matchedSegmentsPerCluster[j] = 1;
205 clusLink.
toIndexedElement(*caloClusterContainerReadHandle, caloClusterCounter - 1);
207 cache.
m_matchMatrix.push_back(std::move(matchedSegmentsPerCluster));
218 unsigned int nMeas{0};
228 time += mmPrd->
time();
231 time += sTgcPrd->
time();
234 constexpr double tdcBinSize = 0.78125;
235 time += tdcBinSize * mdtPrd->
tdc();
241 time += cscPrd->
time();
248 return time / std::max(nMeas, 1u);
263 for (
unsigned int segIndex = 0; segIndex < cache.
m_indexSeg.size(); ++segIndex) {
268 double zSeg = globalPos.z();
282 double inTime = -(-std::abs(zSeg) + globalPos.mag()) * inv_c;
283 double early = -(std::abs(zSeg) + globalPos.mag()) * inv_c;
289 if (timeStatus == 2) {
296 unsigned int segIndexA = segIndex;
299 int timeStatusA = timeStatus;
301 double phiSegA = globalPos.phi();
303 for (
unsigned int segIndexC = 0; segIndexC < cache.
m_indexSeg.size(); segIndexC++) {
308 double zSegC = globalPos.z();
320 double inTime = -(-std::abs(zSegC) + globalPos.mag()) * inv_c;
321 double early = -(std::abs(zSegC) + globalPos.mag()) * inv_c;
327 double phiSegC = globalPos.phi();
337 if (timeStatusA == 0 || timeStatusC == 0)
363 for (
unsigned int clusIndex = 0; clusIndex < cache.
m_indexClus.size();
372 rClus = rClus / std::cosh(clus->
eta());
373 double zClus = rClus * std::sinh(clus->
eta());
374 double tClus = clus->
time();
377 double expectedClusterTimeAC = -(zClus + std::hypot(rClus, zClus)) * inv_c;
378 double expectedClusterTimeCA = -(-zClus + std::hypot(rClus, zClus)) * inv_c;
380 for (
unsigned int segIndex = 0; segIndex < cache.
m_indexSeg.size(); segIndex++) {
388 double zSeg = globalPos.z();
394 double inTime = -(-std::abs(zSeg) + globalPos.mag()) * inv_c;
395 double early = -(std::abs(zSeg) + globalPos.mag()) * inv_c;
403 if ((zSeg > 0 && timeStatus == 2) || (zSeg < 0 && timeStatus == 1))
405 if ((zSeg > 0 && timeStatus == 1) || (zSeg < 0 && timeStatus == 2))
410 if (std::abs(tClus - expectedClusterTimeAC) <
m_cutClusTime ||
424 if (direction == 1) {
425 if (std::abs(tClus - expectedClusterTimeAC) <
m_cutClusTime) {
434 }
else if (direction == -1) {
435 if (std::abs(tClus - expectedClusterTimeCA) <
m_cutClusTime) {
478 for (
unsigned int clusIndex = 0; clusIndex < cache.
m_indexClus.size(); clusIndex++) {
480 for (
unsigned int segIndexA = 0; segIndexA < cache.
m_indexSeg.size(); segIndexA++) {
488 double zSegA = globalPos.z();
497 double inTime = -(-std::abs(zSegA) + globalPos.mag()) * inv_c;
498 double early = -(std::abs(zSegA) + globalPos.mag()) * inv_c;
505 for (
unsigned int segIndexC = 0; segIndexC < cache.
m_indexSeg.size(); segIndexC++) {
513 double zSegC = globalPos.z();
524 double inTime = -(-std::abs(zSegC) + globalPos.mag()) * inv_c;
525 double early = -(std::abs(zSegC) + globalPos.mag()) * inv_c;
538 if (timeStatusA == 0 || timeStatusC == 0)
549 if (timeStatusA == 2)
551 if (timeStatusC == 2)
578 for (
unsigned int clusIndex = 0; clusIndex < cache.
m_indexClus.size();
586 rClus = rClus / cosh(clus->
eta());
587 double zClus = rClus * sinh(clus->
eta());
599 for (; firstCell != lastCell; ++firstCell) {
602 if (cell->time() == 0.)
604 if (cell->energy() < 100.)
611 const double rCell = dde->
r();
612 const double zCell = dde->
z();
613 dr = dr + (rCell - rClus) * (rCell - rClus);
614 dz = dz + (zCell - zClus) * (zCell - zClus);
619 dr = sqrt(dr / nCell);
620 dz = sqrt(dz / nCell);
631 for (
unsigned int segIndex = 0; segIndex < cache.
m_indexSeg.size();
656 Cache& cache)
const {
665 if (!jetContainerReadHandle.
isValid()) {
671 unsigned int jetCounter = 0;
672 for (
const auto *thisJet : *jetContainerReadHandle) {
673 bool isFakeJet =
false;
680 for (; constIt != constItE; ++constIt) {
686 for (
unsigned int clusIndex = 0; clusIndex < cache.
m_indexClus.size();
690 if (jetConst == clus) {
731 writeHandle->SetNumJet(cache.
m_numJet);
734 for (
unsigned int i = 0; i < cache.
m_indexSeg.size(); i++) {
737 for (
unsigned int i = 0; i < cache.
m_indexClus.size(); i++) {
740 writeHandle->SetDecision(decision);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
This file defines helper classes to deal with jet constituents.
An algorithm that can be simultaneously executed in multiple threads.
Gaudi::Property< double > m_thetaCutNCB
Inclanation cut between the segment position and its direction.
SG::WriteHandleKey< BeamBackgroundData > m_beamBackgroundDataWriteHandleKey
Gaudi::Property< double > m_cutDradClusSeg
void SegmentMethod(Cache &cache) const
This function looks at the segments found by the FillMatchMatrix function.
SG::ReadHandleKey< xAOD::JetContainer > m_jetContainerReadHandleKey
ReadHandleKey for JetContainer.
ToolHandle< Muon::IMuonSegmentSelectionTool > m_segmentSelector
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
virtual StatusCode initialize() override
void FindFakeJets(const EventContext &ctx, Cache &cache) const
This function checks whether the matched clusters are contained in any jets.
BeamBackgroundFiller(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKeyArray< Trk::SegmentCollection > m_segmentKeys
ReadHandleKey for Trk::SegmentCollection from CSC.
Gaudi::Property< double > m_cutDrdz
Gaudi::Property< double > m_clusRadiusLow
Gaudi::Property< double > m_cutTimeDiffAC
Gaudi::Property< double > m_cutDphiClusSeg
void ClusterShapeMethod(Cache &cache) const
This function is the implementation of the "Cluster-Shape Method".
void FillBeamBackgroundData(SG::WriteHandle< BeamBackgroundData > &beamBackgroundDataWriteHandle, Cache &cache) const
This function stores all the results in BeamBackgroundData.
void FillMatchMatrix(const EventContext &ctx, Cache &cache) const
This function selects the muon segments with the direction parallel to the beam pipe and calorimeter ...
void OneSidedMethod(Cache &cache) const
This function is the implementation of the "No-Time Method" and the "One-Sided Method".
Gaudi::Property< double > m_clusEnergyCut
Minimum cut on the cluster energy to be considered.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClusterContainerReadHandleKey
ReadHandleKey for CaloClusterContainer.
Gaudi::Property< double > m_cutDphiSegAC
Gaudi::Property< double > m_clusRadiusHigh
Gaudi::Property< double > m_cutClusTime
double GetSegmentTime(const Muon::MuonSegment &pMuonSegment) const
Gaudi::Property< double > m_cutMuonTime
virtual StatusCode execute(const EventContext &ctx) const override
void TwoSidedMethod(Cache &cache) const
This function is the implementation of the "Two-Sided No-Time Method" and the "Two-Sided Method" that...
Data object for each calorimeter readout cell.
This class groups all DetDescr information related to a CaloCell.
ElementLink implementation for ROOT usage.
bool toIndexedElement(BaseConstReference data, index_type elemID, IProxyDict *sg=0)
Set the link to an element given by index and pointer to container.
Class representing clusters from the CSC.
double time() const
Returns the time.
Class to represent MM measurements.
short int time() const
Returns the time (in ns)
Class to represent measurements from the Monitored Drift Tubes.
int tdc() const
Returns the TDC (typically range is 0 to 2500).
This is the common class for 3D segments used in the muon spectrometer.
const Amg::Vector3D & globalDirection() const
global direction
virtual const Amg::Vector3D & globalPosition() const override final
global position
Class to represent sTgc measurements.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
bool isPresent() const
Is the referenced object present in SG?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
This class is the pure abstract base class for all fittable tracking measurements.
Identifier identify() const
return the identifier
virtual bool type(PrepRawDataType type) const
Interface method checking the type.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Base class for all TrackSegment implementations, extends the common MeasurementBase.
const std::vector< const Trk::MeasurementBase * > & containedMeasurements() const
returns the vector of Trk::MeasurementBase objects
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
flt_t time() const
Access cluster time.
virtual double eta() const
The pseudorapidity ( ) of the particle.
CaloClusterCellLink::const_iterator const_cell_iterator
Iterator of the underlying CaloClusterCellLink (explicitly const version)
const_cell_iterator cell_end() const
@ CENTER_MAG
Cluster Centroid ( )
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version)
A vector of jet constituents at the scale used during jet finding.
Type::ObjectType type() const
The full 4-momentum of the particle.
const IParticle * rawConstituent() const
Access the real underlying IParticle.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 3, 1 > Vector3D
StIndex
enum to classify the different station layers in the muon spectrometer
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
@ CaloCluster
The object is a calorimeter cluster.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
std::vector< int > m_resultClus
std::vector< int > m_resultSeg
ElementLinkVector< xAOD::JetContainer > m_indexJet
std::vector< std::vector< int > > m_matchMatrix
ElementLinkVector< xAOD::CaloClusterContainer > m_indexClus
ElementLinkVector< Trk::SegmentCollection > m_indexSeg
std::vector< float > m_drdzClus
std::vector< int > m_resultJet