ATLAS Offline Software
Loading...
Searching...
No Matches
MMTriggerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "MMTriggerTool.h"
6
7namespace NSWL1 {
8
9 MMTriggerTool::MMTriggerTool( const std::string& type, const std::string& name, const IInterface* parent) :
10 base_class(type,name,parent) {}
11
13
14 ATH_MSG_DEBUG( name() << " configuration:");
15 ATH_MSG_DEBUG(" " << std::setw(32) << std::setfill('.') << std::setiosflags(std::ios::left) << m_mmDigitContainer.name() << m_mmDigitContainer.value());
16 ATH_MSG_DEBUG(" " << std::setw(32) << std::setfill('.') << std::setiosflags(std::ios::left) << m_doNtuple.name() << ((m_doNtuple)? "[True]":"[False]")
17 << std::setfill(' ') << std::setiosflags(std::ios::right) );
18
21 ATH_CHECK(m_keyMmDigitContainer.initialize());
22 ATH_CHECK(m_idHelperSvc.retrieve());
23 ATH_CHECK(m_detectorManagerKey.initialize());
24
25 if(m_doNtuple and Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1) {
26 ATH_MSG_ERROR("DoNtuple is not possible in multi-threaded mode");
27 return StatusCode::FAILURE;
28 }
29
31
32 return StatusCode::SUCCESS;
33 }
34
36 m_trigger_diamond_ntrig = std::make_shared<MuonVal::VectorBranch<unsigned int> >(tree, "MM_diamond_ntrig");
37 m_trigger_diamond_bc = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_diamond_bc");
38 m_trigger_diamond_sector = std::make_shared<MuonVal::VectorBranch<char> >(tree, "MM_diamond_sector");
39 m_trigger_diamond_sectorPhi = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_diamond_sectorPhi");
40 m_trigger_diamond_totalCount = std::make_shared<MuonVal::VectorBranch<unsigned int> >(tree, "MM_diamond_totalCount");
41 m_trigger_diamond_iX = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_diamond_iX");
42 m_trigger_diamond_iU = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_diamond_iU");
43 m_trigger_diamond_iV = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_diamond_iV");
44 m_trigger_diamond_xCount = std::make_shared<MuonVal::VectorBranch<unsigned int> >(tree, "MM_diamond_xCount");
45 m_trigger_diamond_uCount = std::make_shared<MuonVal::VectorBranch<unsigned int> >(tree, "MM_diamond_uCount");
46 m_trigger_diamond_age = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_diamond_age");
47 m_trigger_diamond_mx = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_mx");
48 m_trigger_diamond_my = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_my");
49 m_trigger_diamond_Uavg = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_Uavg");
50 m_trigger_diamond_Vavg = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_Vavg");
51 m_trigger_diamond_mxl = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_mxl");
52 m_trigger_diamond_theta = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_theta");
53 m_trigger_diamond_eta = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_eta");
54 m_trigger_diamond_dtheta = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_dtheta");
55 m_trigger_diamond_phi = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_phi");
56 m_trigger_diamond_phiShf = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_diamond_phiShf");
57 m_trigger_diamond_TP_phi_id = std::make_shared<MuonVal::VectorBranch<uint8_t> >(tree, "MM_diamond_TP_phi_id");
58 m_trigger_diamond_TP_R_id = std::make_shared<MuonVal::VectorBranch<uint8_t> >(tree, "MM_diamond_TP_R_id");
59 m_trigger_diamond_TP_dTheta_id = std::make_shared<MuonVal::VectorBranch<uint8_t> >(tree, "MM_diamond_TP_dTheta_id");
60 m_trigger_RZslopes = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_RZslopes");
61 m_trigger_trueEtaRange = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_trueEtaRange");
62 m_trigger_truePtRange = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_truePtRange");
63 m_trigger_VMM = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_VMM");
64 m_trigger_plane = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_plane");
65 m_trigger_station = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_station");
66 m_trigger_strip = std::make_shared<MuonVal::VectorBranch<int> >(tree, "MM_strip");
67 m_trigger_slope = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_slope");
68 m_trigger_trueThe = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_trueThe");
69 m_trigger_truePhi = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_truePhi");
70 m_trigger_trueDth = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_trueDth");
71 m_trigger_trueEtaEnt = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_trueEtaEnt");
72 m_trigger_trueTheEnt = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_trueTheEnt");
73 m_trigger_truePhiEnt = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_truePhiEnt");
74 m_trigger_trueEtaPos = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_trueEtaPos");
75 m_trigger_trueThePos = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_trueThePos");
76 m_trigger_truePhiPos = std::make_shared<MuonVal::VectorBranch<double> >(tree, "MM_truePhiPos");
77
78 tree.addBranch(m_trigger_diamond_ntrig);
79 tree.addBranch(m_trigger_diamond_bc);
80 tree.addBranch(m_trigger_diamond_sector);
81 tree.addBranch(m_trigger_diamond_sectorPhi);
82 tree.addBranch(m_trigger_diamond_totalCount);
83 tree.addBranch(m_trigger_diamond_iX);
84 tree.addBranch(m_trigger_diamond_iU);
85 tree.addBranch(m_trigger_diamond_iV);
86 tree.addBranch(m_trigger_diamond_xCount);
87 tree.addBranch(m_trigger_diamond_uCount);
88 tree.addBranch(m_trigger_diamond_age);
89 tree.addBranch(m_trigger_diamond_mx);
90 tree.addBranch(m_trigger_diamond_my);
91 tree.addBranch(m_trigger_diamond_Uavg);
92 tree.addBranch(m_trigger_diamond_Vavg);
93 tree.addBranch(m_trigger_diamond_mxl);
94 tree.addBranch(m_trigger_diamond_theta);
95 tree.addBranch(m_trigger_diamond_eta);
96 tree.addBranch(m_trigger_diamond_dtheta);
97 tree.addBranch(m_trigger_diamond_phi);
98 tree.addBranch(m_trigger_diamond_phiShf);
99 tree.addBranch(m_trigger_diamond_TP_phi_id);
100 tree.addBranch(m_trigger_diamond_TP_R_id);
101 tree.addBranch(m_trigger_diamond_TP_dTheta_id);
102 tree.addBranch(m_trigger_RZslopes);
103 tree.addBranch(m_trigger_trueEtaRange);
104 tree.addBranch(m_trigger_truePtRange);
105 tree.addBranch(m_trigger_VMM);
106 tree.addBranch(m_trigger_plane);
107 tree.addBranch(m_trigger_station);
108 tree.addBranch(m_trigger_strip);
109 tree.addBranch(m_trigger_slope);
110 tree.addBranch(m_trigger_trueThe);
111 tree.addBranch(m_trigger_truePhi);
112 tree.addBranch(m_trigger_trueDth);
113 tree.addBranch(m_trigger_trueEtaEnt);
114 tree.addBranch(m_trigger_trueTheEnt);
115 tree.addBranch(m_trigger_truePhiEnt);
116 tree.addBranch(m_trigger_trueEtaPos);
117 tree.addBranch(m_trigger_trueThePos);
118 tree.addBranch(m_trigger_truePhiPos);
119 return StatusCode::SUCCESS;
120 }
121
122 StatusCode MMTriggerTool::runTrigger(const EventContext& ctx, Muon::NSW_TrigRawDataContainer* rdo, const bool do_MMDiamonds) const {
123
124 uint64_t event = ctx.eventID().event_number();
125 ATH_MSG_DEBUG("********************************************************* EVENT NUMBER = " << event);
126
128 if(!detManager.isValid()){
129 ATH_MSG_ERROR("Failed to retrieve the MuonDetectorManager conditions object");
130 return StatusCode::FAILURE;
131 }
132
133 const McEventCollection* ptrMcEventCollection = nullptr;
134 const TrackRecordCollection* ptrMuonEntryLayer = nullptr;
135 if(m_isMC){
136 SG::ReadHandle<McEventCollection> readMcEventCollection( m_keyMcEventCollection, ctx );
137 if( !readMcEventCollection.isValid() ){
138 ATH_MSG_ERROR("Cannot retrieve McEventCollection");
139 return StatusCode::FAILURE;
140 }
141 if(m_doTruth) ptrMcEventCollection = readMcEventCollection.cptr();
143 if( !readMuonEntryLayer.isValid() ){
144 ATH_MSG_ERROR("Cannot retrieve MuonEntryLayer");
145 return StatusCode::FAILURE;
146 }
147 if(m_doTruth and m_doNtuple) {
148 ptrMuonEntryLayer = readMuonEntryLayer.cptr();
150 std::map<std::pair<uint64_t, unsigned int>,evInf_entry> Event_Info;
151 ATH_CHECK(load.getTruthInfo(ctx, ptrMcEventCollection, ptrMuonEntryLayer, Event_Info));
152
153 // Extract truth info, if available
154 for (const auto &it : Event_Info) {
155 m_trigger_trueEtaRange->push_back(it.second.eta_ip);
156 m_trigger_truePtRange->push_back(it.second.pt);
157 m_trigger_trueThe->push_back(it.second.theta_ip);
158 m_trigger_truePhi->push_back(it.second.phi_ip);
159 m_trigger_trueDth->push_back(it.second.dtheta); // theta_pos-theta_ent
160 m_trigger_trueEtaPos->push_back(it.second.eta_pos);
161 m_trigger_trueThePos->push_back(it.second.theta_pos);
162 m_trigger_truePhiPos->push_back(it.second.phi_pos);
163 m_trigger_trueEtaEnt->push_back(it.second.eta_ent);
164 m_trigger_trueTheEnt->push_back(it.second.theta_ent);
165 m_trigger_truePhiEnt->push_back(it.second.phi_ent);
166 }
167 }
168 }
169
170 SG::ReadHandle<MmDigitContainer> readMmDigitContainer( m_keyMmDigitContainer, ctx );
171 if( !readMmDigitContainer.isValid() ){
172 ATH_MSG_ERROR("Cannot retrieve MmDigitContainer");
173 return StatusCode::FAILURE;
174 }
175
176 for (const MmDigitCollection* digitCollection : *readMmDigitContainer) {
177
178 std::vector<std::shared_ptr<MMT_Hit> > ev_hits;
179 for (const MmDigit* digit : *digitCollection) {
180 const Identifier id = digit->identify();
181 if (not m_idHelperSvc->isMM(id)) continue;
182
183 const std::string stationName = m_idHelperSvc->chamberNameString(id);
184 const int stationEta = m_idHelperSvc->stationEta(id);
185 const int stationPhi = m_idHelperSvc->stationPhi(id);
186 const int sector = m_idHelperSvc->sector(id);
187 const int multiplet = m_idHelperSvc->mmIdHelper().multilayer(id);
188 const int gasGap = m_idHelperSvc->mmIdHelper().gasGap(id);
189
190 const int channel = m_idHelperSvc->mmIdHelper().channel(id);
191 // Checking whether strip exceeds allowed ranges
192 const MuonGM::MMReadoutElement* readout = detManager->getMMReadoutElement(id);
193 if (channel < 1 or channel > (readout->getDesign(id))->totalStrips) continue;
194
195 const float stripTime = digit->stripResponseTime();
196 // Checking positive digitization time
197 if (stripTime < 0.) continue;
198 const int BC = std::ceil(stripTime/25.);
199 ev_hits.emplace_back(std::make_shared<MMT_Hit>(id, stationName, stationEta, stationPhi, sector, multiplet, gasGap, channel, stripTime, BC, detManager.cptr()));
200
201 if (ev_hits.back()->infSlope()) {
202 ATH_MSG_WARNING("Infinite slope, removing hit");
203 ev_hits.pop_back();
204 continue;
205 }
206 if (m_doNtuple) {
207 m_trigger_VMM->push_back(ev_hits.back()->getVMM());
208 m_trigger_plane->push_back(ev_hits.back()->getPlane());
209 m_trigger_station->push_back(ev_hits.back()->getStationEta());
210 m_trigger_strip->push_back(ev_hits.back()->getChannel());
211 m_trigger_RZslopes->push_back(ev_hits.back()->getRZSlope());
212 }
213 }
214
215 // Go ahead when hits are more than X+UV thresholds
216 if (do_MMDiamonds and ev_hits.size() >= (m_diamond->getXthreshold()+m_diamond->getUVthreshold())) {
217 const bool isLarge = (std::ranges::all_of(ev_hits, [](const auto &hit) { return hit->getSector() == 'L'; }));
218 const char sector = (isLarge) ? 'L' : 'S';
219 const char side = (std::ranges::all_of(ev_hits, [](const auto &hit) { return hit->getStationEta() < 0; })) ? 'C' : 'A';
220 const int sectorPhi = ev_hits[0]->getSectorPhi();
221 const bool allSectorPhi = (std::ranges::all_of(ev_hits, [&](const auto &hit) { return hit->getSectorPhi() == sectorPhi; }));
222 if (not allSectorPhi) {
223 ATH_MSG_ERROR("Available digits belongs to different sectors IDs, unable to assign an unique ID in output RDO");
224 return StatusCode::FAILURE;
225 }
226 const bool isEta1 = (std::ranges::all_of(ev_hits, [](const auto &hit) { return std::abs(hit->getStationEta()) == 1; }));
227
228 // Setup roads
229 std::vector<MMT_Road> ev_roads;
230 m_diamond->createRoads(ev_roads, isLarge, isEta1);
231
232 // Evaluate coincidences
233 std::vector<slope_t> diamondSlopes;
234 m_diamond->findDiamonds(ev_hits, ev_roads, diamondSlopes, sectorPhi);
235
236 // Store output, if any, in debug ntuple (if enabled) and in trigger RDO
237 if (not diamondSlopes.empty()) {
238 if (m_doNtuple) {
239 m_trigger_diamond_ntrig->push_back(diamondSlopes.size());
240 for (const auto &slope : diamondSlopes) {
241 m_trigger_diamond_sector->push_back(sector);
242 m_trigger_diamond_sectorPhi->push_back(sectorPhi);
243 m_trigger_diamond_bc->push_back(slope.BC);
244 m_trigger_diamond_totalCount->push_back(slope.totalCount);
245 m_trigger_diamond_xCount->push_back(slope.xCount);
246 m_trigger_diamond_uCount->push_back(slope.uCount);
247 m_trigger_diamond_iX->push_back(slope.iRoad);
248 m_trigger_diamond_iU->push_back(slope.iRoadu);
249 m_trigger_diamond_iV->push_back(slope.iRoadv);
250 m_trigger_diamond_age->push_back(slope.age);
251 m_trigger_diamond_mx->push_back(slope.mx);
252 m_trigger_diamond_my->push_back(slope.my);
253 m_trigger_diamond_Uavg->push_back(slope.uavg);
254 m_trigger_diamond_Vavg->push_back(slope.vavg);
255 m_trigger_diamond_mxl->push_back(slope.mxl);
256 m_trigger_diamond_theta->push_back(slope.theta);
257 m_trigger_diamond_eta->push_back(slope.eta);
258 m_trigger_diamond_dtheta->push_back(slope.dtheta);
259 m_trigger_diamond_phi->push_back(slope.phi);
260 m_trigger_diamond_phiShf->push_back(slope.phiShf);
261 }
262 }
263
264 // MM RDO filling below
265 std::vector<int> slopeBC;
266 for (const auto &slope : diamondSlopes) slopeBC.push_back(slope.BC);
267 std::ranges::sort(slopeBC);
268 slopeBC.erase( std::unique(slopeBC.begin(), slopeBC.end()), slopeBC.end() );
269 for (const auto bc : slopeBC) {
270 Muon::NSW_TrigRawData* trigRawData = new Muon::NSW_TrigRawData(sectorPhi-1, side, bc);
271
272 for (const auto &slope : diamondSlopes) {
273 if (bc == slope.BC) {
275
276 // Phi-id - here use local phi (not phiShf)
277 uint8_t phi_id = 0;
278 if (slope.phi > m_phiMax || slope.phi < m_phiMin) trigRawDataSegment->setPhiIndex(phi_id);
279 else {
280 uint8_t nPhi = (1<<m_phiBits) -2; // To accomodate the new phi-id encoding prescription around 0
281 float phiSteps = (m_phiMax - m_phiMin)/nPhi;
282 for (uint8_t i=0; i<nPhi; i++) {
283 if ((slope.phi) < (m_phiMin+i*phiSteps)) {
284 phi_id = i;
285 break;
286 }
287 }
288 trigRawDataSegment->setPhiIndex(phi_id);
289 }
290 if (m_doNtuple) m_trigger_diamond_TP_phi_id->push_back(phi_id);
291
292 // R-id
293 double extrapolatedR = 7824.46*std::abs(std::tan(slope.theta)); // The Z plane is a fixed value, taken from SL-TP documentation
294 uint8_t R_id = 0;
295 if (extrapolatedR > m_rMax || extrapolatedR < m_rMin) trigRawDataSegment->setRIndex(R_id);
296 else {
297 uint8_t nR = (1<<m_rBits) -1;
298 float Rsteps = (m_rMax - m_rMin)/nR;
299 for (uint8_t j=0; j<nR; j++) {
300 if (extrapolatedR < (m_rMin+j*Rsteps)) {
301 R_id = j;
302 break;
303 }
304 }
305 trigRawDataSegment->setRIndex(R_id);
306 }
307 if (m_doNtuple) m_trigger_diamond_TP_R_id->push_back(R_id);
308
309 // DeltaTheta-id
310 uint8_t dTheta_id = 0;
311 if (slope.dtheta > m_dThetaMax || slope.dtheta < m_dThetaMin) trigRawDataSegment->setDeltaTheta(dTheta_id);
312 else {
313 uint8_t ndTheta = (1<<m_dThetaBits) -1;
314 float dThetaSteps = (m_dThetaMax - m_dThetaMin)/ndTheta;
315 for (uint8_t k=0; k<ndTheta; k++) {
316 if ((slope.dtheta) < (m_dThetaMin+k*dThetaSteps)) {
317 dTheta_id = k;
318 break;
319 }
320 }
321 trigRawDataSegment->setDeltaTheta(dTheta_id);
322 }
323 if (m_doNtuple) m_trigger_diamond_TP_dTheta_id->push_back(dTheta_id);
324
325 // Low R-resolution bit
326 trigRawDataSegment->setLowRes(slope.lowRes);
327
328 trigRawData->push_back(trigRawDataSegment);
329 }
330 }
331 rdo->push_back(trigRawData);
332 }
333 }
334 }
335 else {
336 ATH_MSG_DEBUG("Available hits are " << ev_hits.size() << ", less than X+UV threshold, skipping digit collection");
337 }
338 }
339
340 return StatusCode::SUCCESS;
341 }
342}//end namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AtlasHitsVector< TrackRecord > TrackRecordCollection
value_type push_back(value_type pElem)
Add an element to the end of the collection.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
An MMReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station con...
const MuonChannelDesign * getDesign(const Identifier &id) const
returns the MuonChannelDesign class for the given identifier
void setDeltaTheta(uint8_t deltaTheta)
Gaudi::Property< int > m_diamOverlapStereoDown
Gaudi::Property< float > m_rMax
Gaudi::Property< int > m_diamXthreshold
MMTriggerTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< float > m_phiMax
Gaudi::Property< float > m_dThetaMax
Gaudi::Property< float > m_phiMin
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< int > m_diamUVthreshold
Gaudi::Property< int > m_rBits
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detectorManagerKey
virtual StatusCode initialize() override
Gaudi::Property< int > m_phiBits
StatusCode attachBranches(MuonVal::MuonTesterTree &tree) override
std::unique_ptr< MMT_Diamond > m_diamond
Gaudi::Property< int > m_diamOverlapEtaUp
Gaudi::Property< bool > m_doNtuple
Gaudi::Property< int > m_dThetaBits
Gaudi::Property< float > m_rMin
Gaudi::Property< std::string > m_mmDigitContainer
Gaudi::Property< int > m_diamOverlapStereoUp
SG::ReadHandleKey< MmDigitContainer > m_keyMmDigitContainer
StatusCode runTrigger(const EventContext &ctx, Muon::NSW_TrigRawDataContainer *rdo, const bool do_MMDiamonds) const override
Gaudi::Property< float > m_dThetaMin
SG::ReadHandleKey< McEventCollection > m_keyMcEventCollection
Gaudi::Property< bool > m_uv
Gaudi::Property< bool > m_doTruth
SG::ReadHandleKey< TrackRecordCollection > m_keyMuonEntryLayer
Gaudi::Property< bool > m_isMC
Gaudi::Property< int > m_diamRoadSize
Gaudi::Property< int > m_diamOverlapEtaDown
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
PadEmulatorCoincidences.
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
TChain * tree