ATLAS Offline Software
CscDataPreparator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CscDataPreparator.h"
6 
9 
10 // --------------------------------------------------------------------------------
11 // --------------------------------------------------------------------------------
12 
14 
15 // --------------------------------------------------------------------------------
16 // --------------------------------------------------------------------------------
17 
19  const std::string& name,
20  const IInterface* parent):
22 {
23 }
24 
25 // --------------------------------------------------------------------------------
26 // --------------------------------------------------------------------------------
27 
29 {
30 
31  ATH_CHECK(m_idHelperSvc.retrieve());
32 
33  ATH_CHECK(m_cscPrepContainerKey.initialize(!m_cscPrepContainerKey.empty()));
34 
35  return StatusCode::SUCCESS;
36 }
37 
38 // --------------------------------------------------------------------------------
39 // --------------------------------------------------------------------------------
40 
42  TrigL2MuonSA::MuonRoad& muonRoad,
43  TrigL2MuonSA::CscHits& cscHits) const
44 {
45 
46  // Clear the output
47  cscHits.clear();
48 
49  // Get CSC container
50  if(!m_cscPrepContainerKey.empty()){
51  auto cscPrepContainerHandle = SG::makeHandle(m_cscPrepContainerKey, ctx);
52  const Muon::CscPrepDataContainer* cscPrepContainer = cscPrepContainerHandle.cptr();
53  if (!cscPrepContainerHandle.isValid()) {
54  ATH_MSG_ERROR("Cannot retrieve CSC PRD Container key: " << m_cscPrepContainerKey.key());
55  return StatusCode::FAILURE;
56  }
57 
58  // Loop over collections
59  for( const Muon::CscPrepDataCollection* cscCol : *cscPrepContainer ){
60  if( cscCol==nullptr ) continue;
61  cscHits.reserve( cscHits.size() + cscCol->size() );
62  // Loop over data in the collection
63  for( const Muon::CscPrepData* prepData : *cscCol ) {
64  if( prepData==nullptr ) continue;
65 
66  // Road info
68  double aw = muonRoad.aw[chamber][0];
69  double bw = muonRoad.bw[chamber][0];
70  //double rWidth = muonRoad.rWidth[chamber][0];
71  double phiw = muonRoad.phi[4][0];//roi_descriptor->phi(); //muonRoad.phi[chamber][0];
72 
73  //cluster status
74  bool isunspoiled = IsUnspoiled (prepData->status());
75 
76 
77  // Create new digit
78  TrigL2MuonSA::CscHitData cscHit{};
79  cscHit.StationName = m_idHelperSvc->cscIdHelper().stationName( prepData->identify() );
80  cscHit.StationEta = m_idHelperSvc->cscIdHelper().stationEta( prepData->identify() );
81  cscHit.StationPhi = m_idHelperSvc->cscIdHelper().stationPhi( prepData->identify() );
82  cscHit.ChamberLayer = (true==isunspoiled) ? 1 : 0;
83  cscHit.WireLayer = m_idHelperSvc->cscIdHelper().wireLayer( prepData->identify() );
84  cscHit.MeasuresPhi = m_idHelperSvc->cscIdHelper().measuresPhi( prepData->identify() );
85  cscHit.Strip = m_idHelperSvc->cscIdHelper().strip( prepData->identify() );
86  cscHit.Chamber = chamber;
87  cscHit.StripId = (cscHit.StationName << 18)
88  | ((cscHit.StationEta + 2) << 16) | (cscHit.StationPhi << 12)
89  | (cscHit.WireLayer << 9) | (cscHit.MeasuresPhi << 8) | (cscHit.Strip);
90  cscHit.eta = prepData->globalPosition().eta();
91  cscHit.phi = prepData->globalPosition().phi();
92  cscHit.r = prepData->globalPosition().perp();
93  cscHit.z = prepData->globalPosition().z();
94  cscHit.charge = prepData->charge();
95  cscHit.time = prepData->time();
96  cscHit.resolution = std::sqrt( prepData->localCovariance()(0,0) );
97  cscHit.Residual = ( cscHit.MeasuresPhi==0 ) ? calc_residual( aw, bw, cscHit.z, cscHit.r ) : calc_residual_phi( aw,bw,phiw, cscHit.phi, cscHit.z);
98  cscHit.isOutlier = 0;
99  /*if( std::abs(cscHit.Residual) > rWidth ) {
100  cscHit.isOutlier = 2;
101  }*/
102  double width = (cscHit.MeasuresPhi) ? 250. : 100.;
103  if( std::abs(cscHit.Residual)>width ){
104  cscHit.isOutlier=1;
105  if( std::abs(cscHit.Residual)>3.*width ){
106  cscHit.isOutlier=2;
107  }
108  }
109 
110  cscHits.push_back( cscHit );
111 
112  // Debug print
113  ATH_MSG_DEBUG("CSC Hits: "
114  << "SN=" << cscHit.StationName << ","
115  << "SE=" << cscHit.StationEta << ","
116  << "SP=" << cscHit.StationPhi << ","
117  << "CL=" << cscHit.ChamberLayer << ","
118  << "WL=" << cscHit.WireLayer << ","
119  << "MP=" << cscHit.MeasuresPhi << ","
120  << "St=" << cscHit.Strip << ","
121  << "ID=" << cscHit.StripId << ","
122  << "eta=" << cscHit.eta << ","
123  << "phi=" << cscHit.phi << ","
124  << "r=" << cscHit.r << ","
125  << "z=" << cscHit.z << ","
126  << "q=" << cscHit.charge << ","
127  << "t=" << cscHit.time << ","
128  << "Rs=" << cscHit.Residual << ","
129  << "OL=" << cscHit.isOutlier);
130  }
131  }
132  }
133 
134  //
135  return StatusCode::SUCCESS;
136 }
137 
138 // --------------------------------------------------------------------------------
139 // --------------------------------------------------------------------------------
140 
141 double TrigL2MuonSA::CscDataPreparator::calc_residual(double aw,double bw,double x,double y) const
142 {
143  const double ZERO_LIMIT = 1e-4;
144  if( std::abs(aw) < ZERO_LIMIT ) return y-bw;
145  double ia = 1/aw;
146  double iaq = ia*ia;
147  double dz = x - (y-bw)*ia;
148  return dz/std::sqrt(1.+iaq);
149 
150 }
151 
152 
153 double TrigL2MuonSA::CscDataPreparator::calc_residual_phi( double aw, double bw, double phiw, double hitphi, double hitz) const
154 {
155 
156  double roadr = hitz*aw + bw;
157 
158  return roadr*( std::cos(phiw)*std::sin(hitphi)-std::sin(phiw)*std::cos(hitphi) );
159 
160 }
161 
162 // --------------------------------------------------------------------------------
163 // --------------------------------------------------------------------------------
164 
165 
168  return true;
169 
170  return false;
171 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
ActiveStoreSvc.h
TrigL2MuonSA::CscHitData
Definition: CscData.h:14
TrigL2MuonSA::CscDataPreparator::calc_residual_phi
double calc_residual_phi(double aw, double bw, double phiw, double hitphi, double hitz) const
Definition: CscDataPreparator.cxx:153
calibdata.chamber
chamber
Definition: calibdata.py:31
IsUnspoiled
bool IsUnspoiled(Muon::CscClusterStatus status)
Definition: CscDataPreparator.cxx:166
TrigL2MuonSA::CscDataPreparator::CscDataPreparator
CscDataPreparator(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CscDataPreparator.cxx:18
TrigL2MuonSA::CscHitData::StationName
unsigned int StationName
Definition: CscData.h:15
TrigL2MuonSA::MuonRoad::bw
double bw[N_STATION][N_SECTOR]
Definition: MuonRoad.h:84
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
TrigL2MuonSA::CscHits
std::vector< CscHitData > CscHits
Definition: CscData.h:40
x
#define x
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
TrigL2MuonSA::MuonRoad::aw
double aw[N_STATION][N_SECTOR]
Definition: MuonRoad.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigL2MuonSA::CscDataPreparator::prepareData
StatusCode prepareData(const EventContext &ctx, TrigL2MuonSA::MuonRoad &muonRoad, TrigL2MuonSA::CscHits &cscHits) const
Definition: CscDataPreparator.cxx:41
TrigL2MuonSA::MuonRoad
Definition: MuonRoad.h:20
Muon::CscPrepData
Class representing clusters from the CSC.
Definition: CscPrepData.h:39
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CscDataPreparator.h
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
ZERO_LIMIT
const float ZERO_LIMIT
Definition: VP1TriggerHandleL2.cxx:37
TrigL2MuonSA::MuonRoad::phi
double phi[N_STATION][N_SECTOR]
Definition: MuonRoad.h:85
Muon::CscStatusUnspoiled
@ CscStatusUnspoiled
Clean cluster with precision fit.
Definition: CscClusterStatus.h:26
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TrigL2MuonSA::CscDataPreparator::calc_residual
double calc_residual(double aw, double bw, double x, double y) const
Definition: CscDataPreparator.cxx:141
TrigMuonDefs.h
y
#define y
Muon::CscStatusSplitUnspoiled
@ CscStatusSplitUnspoiled
Clean cluster with precision fit after split cluster.
Definition: CscClusterStatus.h:59
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
TrigL2MuonSA::CscDataPreparator::initialize
virtual StatusCode initialize() override
Definition: CscDataPreparator.cxx:28
merge.status
status
Definition: merge.py:16
CSC
@ CSC
Definition: RegSelEnums.h:34
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Muon::CscClusterStatus
CscClusterStatus
Enum to represent the cluster status - see the specific enum values for more details.
Definition: CscClusterStatus.h:23
AthAlgTool
Definition: AthAlgTool.h:26