ATLAS Offline Software
Loading...
Searching...
No Matches
sTGCPRDVariables.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9namespace MuonPRDTest {
10 sTGCPRDVariables::sTGCPRDVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
11 PrdTesterModule(tree, "PRD_sTGC", msglvl), m_key{container_name} {}
13
14 bool sTGCPRDVariables::fill(const EventContext& ctx) {
15 m_externalPush = false;
16 ATH_MSG_DEBUG("do fillsTGCPRDVariables()");
17 const MuonGM::MuonDetectorManager* MuonDetMgr = getDetMgr(ctx);
18 if (!MuonDetMgr) { return false; }
20 if (!stgcprdContainer.isValid()) {
21 ATH_MSG_FATAL("Failed to retrieve prd container " << m_key.fullKey());
22 return false;
23 }
24
25 ATH_MSG_DEBUG("retrieved sTGC PRD Container with size " << stgcprdContainer->size());
26
27 if (stgcprdContainer->size() == 0) ATH_MSG_DEBUG(" sTGC PRD Container empty ");
28 unsigned int n_PRD{0};
29 for(const Muon::sTgcPrepDataCollection* coll : *stgcprdContainer ) {
30 for (unsigned int item=0; item<coll->size(); item++) {
31 const Muon::sTgcPrepData* prd = coll->at(item);
32 Identifier Id = prd->identify();
33
34 m_NSWsTGC_PRD_id.push_back(Id);
35 m_NSWsTGC_PRD_charge.push_back(prd->charge());
36
38 if (!det) {
39 ATH_MSG_ERROR("The sTGC hit "<<idHelperSvc()->toString(Id)<<" does not have a detector element attached. That should actually never happen");
40 return false;
41 }
42
43 Amg::Vector3D pos = prd->globalPosition();
44 Amg::Vector2D loc_pos(0., 0.);
45 det->surface(Id).globalToLocal(pos, Amg::Vector3D(0., 0., 0.), loc_pos);
46
47 double err_x = prd->localCovariance()(0,0);
48 double err_y = ( prd->localCovariance().rows()==2)? prd->localCovariance()(1,1) : 0.;
49
50 ATH_MSG_DEBUG( "sTgc PRD local pos.: x=" << std::setw(6) << std::setprecision(2) << loc_pos[0]
51 << ", ex=" << std::setw(6) << std::setprecision(2) << err_x
52 << ", y=" << std::setw(6) << std::setprecision(2) << loc_pos[1]
53 << ", ey=" << std::setw(6) << std::setprecision(2) << err_y );
54
55 m_NSWsTGC_PRD_globalPos.push_back(pos);
56
57 m_NSWsTGC_PRD_localPosX.push_back(loc_pos[0]);
58 m_NSWsTGC_PRD_localPosY.push_back(loc_pos[1]);
59 m_NSWsTGC_PRD_covMatrix_1_1.push_back(err_x);
60 m_NSWsTGC_PRD_covMatrix_2_2.push_back(err_y);
61
62 if(m_applyFilter && !m_filteredChamb.count(coll->identify())){
63 ATH_MSG_VERBOSE("Do not dump measurements from " << idHelperSvc()->toStringChamber(coll->identify()));
64 continue;
65 }
66 for(const Muon::sTgcPrepData* prd: *coll){
67 dump(*prd);
68 ++n_PRD;
69 }
70 }
71 }
72 m_NSWsTGC_nPRD = n_PRD;
73 ATH_MSG_DEBUG("finished fillsTGCPRDVariables()");
74 m_filteredPRDs.clear();
75 m_filteredChamb.clear();
76 return true;
77 }
78
80 m_externalPush=true;
81 return dump(prd);
82 }
83
87
89 m_applyFilter=true;
90 m_filteredChamb.insert(idHelperSvc()->chamberId(detEle.identify()));
91 }
92
94 const Identifier Id = prd.identify();
95
96
97 if (m_filteredPRDs.count(Id)) {
98 ATH_MSG_VERBOSE("The hit has already been added "<<idHelperSvc()->toString(Id));
99 return m_filteredPRDs.at(Id);
100 }
101
102 m_NSWsTGC_PRD_id.push_back(Id);
103 m_NSWsTGC_PRD_charge.push_back(prd.charge());
104
106
107 Amg::Vector3D pos = prd.globalPosition();
108 Amg::Vector2D loc_pos{Amg::Vector2D::Zero()};
109 det->surface(Id).globalToLocal(pos, Amg::Vector3D::Zero(), loc_pos);
110
111 double err_x = prd.localCovariance()(0,0);
112 double err_y = prd.localCovariance().rows()==2 ? prd.localCovariance()(1,1) : 0.;
113
114 ATH_MSG_DEBUG( "sTgc PRD local pos.: x=" << std::setw(6) << std::setprecision(2) << loc_pos[0]
115 << ", ex=" << std::setw(6) << std::setprecision(2) << err_x
116 << ", y=" << std::setw(6) << std::setprecision(2) << loc_pos[1]
117 << ", ey=" << std::setw(6) << std::setprecision(2) << err_y );
118
119 m_NSWsTGC_PRD_globalPos.push_back(pos);
120
121 m_NSWsTGC_PRD_covMatrix_1_1.push_back(err_x);
122 m_NSWsTGC_PRD_covMatrix_2_2.push_back(err_y);
123
124
125 m_NSWsTGC_PRD_charge.push_back(prd.charge());
126
127 // determine the time of the strip with the highest charge
128 short int prdTime = prd.time();
129 if(idHelperSvc()->stgcIdHelper().channelType(Id) == sTgcIdHelper::sTgcChannelTypes::Strip) {
130 int maxCharge{-SHRT_MAX};
131 std::vector<int> stripCharges = prd.stripCharges();
132 for (int i = 0; i < static_cast<int>(stripCharges.size()); ++i) {
133 if (stripCharges.at(i) > maxCharge) {
134 maxCharge = stripCharges.at(i);
135 prdTime = prd.stripTimes().at(i);
136 }
137 }
138 }
139 m_NSWsTGC_PRD_time.push_back(prdTime);
140 m_NSWsTGC_PRD_nStrips.push_back(prd.rdoList().size());
141
143 m_NSWsTGC_PRD_stripTime.push_back(prd.stripTimes());
145
146 m_stgcAuthor.push_back(static_cast<uint8_t>(prd.author()));
147 m_stgcQuality.push_back(static_cast<uint8_t>(prd.quality()));
148
149
150 unsigned idx = m_filteredPRDs.size();
151 if (m_externalPush) {
152 m_filteredPRDs.insert(std::make_pair(Id, idx));
153 }
154
155 return idx;
156 }
157}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
An sTgcReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station c...
const MuonGM::MuonDetectorManager * getDetMgr(const EventContext &ctx) const
const Muon::IMuonIdHelperSvc * idHelperSvc() const
PrdTesterModule(MuonTesterTree &tree, const std::string &grp_name, MSG::Level msglvl)
std::unordered_map< Identifier, unsigned int > m_filteredPRDs
Set of particular chambers to be dumped.
VectorBranch< double > & m_NSWsTGC_PRD_covMatrix_1_1
VectorBranch< uint8_t > & m_stgcAuthor
VectorBranch< double > & m_NSWsTGC_PRD_localPosY
VectorBranch< short > & m_NSWsTGC_PRD_time
bool declare_keys() override final
bool m_applyFilter
Apply a filter to dump the prds.
MatrixBranch< int > & m_NSWsTGC_PRD_stripCharge
bool m_externalPush
Flag telling whether an external prd has been pushed.
sTGCPRDVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
Standard constructor taking the MuonTesterTree as parent The container name under which the MicroMega...
void dumpAllHitsInChamber(const MuonGM::sTgcReadoutElement &detEle)
Adds all hits in this particular chamber to the output n-tuple.
VectorBranch< double > & m_NSWsTGC_PRD_covMatrix_2_2
SG::ReadHandleKey< Muon::sTgcPrepDataContainer > m_key
ScalarBranch< unsigned int > & m_NSWsTGC_nPRD
sTgcIdentifierBranch m_NSWsTGC_PRD_id
VectorBranch< double > & m_NSWsTGC_PRD_localPosX
MatrixBranch< uint16_t > & m_NSWsTGC_PRD_stripChannel
bool fill(const EventContext &ctx) override final
The fill method checks if enough information is provided such that the branch is cleared from the inf...
VectorBranch< int > & m_NSWsTGC_PRD_charge
unsigned int push_back(const Muon::sTgcPrepData &prd)
Adds a prd to the output tree.
void enableSeededDump()
Dumps only hits which are marked by the dumpAllHitsInChamber method.
unsigned int dump(const Muon::sTgcPrepData &prd)
VectorBranch< int > & m_NSWsTGC_PRD_nStrips
VectorBranch< uint8_t > & m_stgcQuality
std::unordered_set< Identifier > m_filteredChamb
Set of chambers to be dumped.
ThreeVectorBranch m_NSWsTGC_PRD_globalPos
MatrixBranch< short > & m_NSWsTGC_PRD_stripTime
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
TTree * tree() override final
Returns the underlying TTree object.
Class to represent sTgc measurements.
Quality quality() const
int charge() const
Returns the bcBitMap of this PRD bit2 for Previous BC, bit1 for Current BC, bit0 for Next BC.
Author author() const
const std::vector< uint16_t > & stripNumbers() const
returns the list of strip numbers
short int time() const
virtual const Amg::Vector3D & globalPosition() const override final
Returns the global position.
const std::vector< int > & stripCharges() const
returns the list of charges
virtual const MuonGM::sTgcReadoutElement * detectorElement() const override final
Returns the detector element corresponding to this PRD.
const std::vector< short int > & stripTimes() const
returns the list of times
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Identifier identify() const
return the identifier
const Amg::MatrixX & localCovariance() const
return const ref to the error matrix
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
MuonPrepDataCollection< sTgcPrepData > sTgcPrepDataCollection
-event-from-file