ATLAS Offline Software
Loading...
Searching...
No Matches
AFPToFAlgorithm.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* AFPToFAlgorithm
6*
7*
8*/
9
10#include "AFPToFAlgorithm.h"
13
14
16
17
19 using namespace Monitored;
20
26
27 // We must declare to the framework in initialize what SG objects we are going to use
28 SG::ReadHandleKey<xAOD::AFPToFHitContainer> afpToFHitContainerKey("AFPToFHits");
30 SG::ReadHandleKey<xAOD::AFPTrackContainer> afpTrackContainerKey( "AFPTracks" );
31 ATH_CHECK( m_afpTrackContainerKey.initialize() );
32
33 ATH_MSG_INFO( "BunchCrossingKey initialization (ToF)" );
34 ATH_CHECK(m_bunchCrossingKeyToF.initialize());
35 ATH_MSG_INFO( "initialization completed (ToF)" );
36
38}
39
40
41StatusCode AFPToFAlgorithm::fillHistograms( const EventContext& ctx ) const {
42 using namespace Monitored;
43
44 const unsigned NTRAINS = 4;
45 const unsigned NBARS = 4;
46 const unsigned NSIDES = 2;
47 enum { FRONT, MIDDLE, END, NPOS } position = NPOS;
48
49 auto bcidAllToF = Monitored::Scalar<int>("bcidAllToF", 0);
50 Monitored::Scalar<int> bcidToF[NPOS] =
51 { Monitored::Scalar<int>("bcidFrontToF", 0),
52 Monitored::Scalar<int>("bcidMiddleToF", 0),
53 Monitored::Scalar<int>("bcidEndToF", 0) };
54
55 // Declare the quantities which should be monitored
56 auto lb = Monitored::Scalar<int>("lb", 0);
57 auto nTofHits = Monitored::Scalar<int>("nTofHits", 1);
58 auto trainID = Monitored::Scalar<int>("trainID", 0);
59 auto barInTrainID = Monitored::Scalar<int>("barInTrainID", 0);
60
61 auto ToFHits_MU_Weight = Monitored::Scalar<float>("ToFHits_MU_Weight", 0.0);
62 auto muPerBXToF = Monitored::Scalar<float>("muPerBXToF", 0.0);
63
64 auto numberOfHit = Monitored::Scalar<int>("numberOfHit", 0);
65 auto barInTrainIDSide = Monitored::Scalar<int>("barInTrainIDSide", 0);
66 auto barInTrainAll = Monitored::Scalar<int>("barInTrainAll", 0);
67 auto ToFHits_side = Monitored::Scalar<int>("ToFHits_side", 0);
68
69 auto lbAandCToFEvents = Monitored::Scalar<int>("lbAandCToFEvents", 0);
70 Monitored::Scalar<int> lbToFEvents[NSIDES] =
71 { Monitored::Scalar<int>("lbAToFEvents", 0),
72 Monitored::Scalar<int>("lbCToFEvents", 0) };
73
74 // per-mu TH1F variables
75 auto lbToFTrainAll = Monitored::Scalar<int>("lbToFTrainAll", 0);
76 auto weightToFTrainAll = Monitored::Scalar<float>("weightToFTrainAll", 0.0);
77 auto lbToFTrainFront = Monitored::Scalar<int>("lbToFTrainFront", 0);
78 auto weightToFTrainFront = Monitored::Scalar<float>("weightToFTrainFront", 0.0);
79 auto lbToFTrainMiddle = Monitored::Scalar<int>("lbToFTrainMiddle", 0);
80 auto weightToFTrainMiddle = Monitored::Scalar<float>("weightToFTrainMiddle", 0.0);
81 auto lbToFTrainEnd = Monitored::Scalar<int>("lbToFTrainEnd", 0);
82 auto weightToFTrainEnd = Monitored::Scalar<float>("weightToFTrainEnd", 0.0);
83 auto lbToFBar = Monitored::Scalar<int>("lbToFBar", 0);
84 auto lbToFBar_Weight = Monitored::Scalar<float>("lbToFBar_Weight", 0.0);
85
87 lb = eventInfo->lumiBlock();
88 lbAandCToFEvents = eventInfo->lumiBlock();
89 muPerBXToF = lbAverageInteractionsPerCrossing(ctx);
90
91 if (muPerBXToF == 0.0) {
92 ATH_MSG_DEBUG("AverageInteractionsPerCrossing is 0, forcing to 1.0");
93 muPerBXToF=1.0;
94 }
95
96 ToFHits_MU_Weight = 1/muPerBXToF;
97 lbToFBar_Weight = 1/muPerBXToF;
98 weightToFTrainAll = 1/muPerBXToF;
99 weightToFTrainFront = 1/muPerBXToF;
100 weightToFTrainMiddle = 1/muPerBXToF;
101 weightToFTrainEnd = 1/muPerBXToF;
102
103 for(unsigned int s = 0; s < NSIDES; s++)
104 {
105 lbToFEvents[s] = eventInfo->lumiBlock();
106 }
107
108 fill("AFPToFTool", lb, muPerBXToF);
109
110 // BCX handler
111 const unsigned int tempBCID = eventInfo->bcid();
113 if (!bcidHdlToF.isValid()) {
114 ATH_MSG_ERROR( "Unable to retrieve BunchCrossing conditions object (ToF)" );
115 }
116 const BunchCrossingCondData* bcDataToF{*bcidHdlToF};
117
118 // Classifying bunches by position in train (Front, Middle, End)
119 if(bcDataToF->isFilled(tempBCID))
120 {
121 bcidAllToF = tempBCID;
122 fill("AFPToFTool", bcidAllToF);
123 if(!bcDataToF->isFilled(tempBCID-1))
124 {
125 position = FRONT;
126 }
127 else if(bcDataToF->isFilled(tempBCID+1))
128 {
129 position = MIDDLE;
130 }
131 else
132 {
133 position = END;
134 }
135 bcidToF[position] = tempBCID;
136 fill("AFPToFTool", bcidToF[position]);
137 }
138
139
141 if(! afpToFHitContainer.isValid())
142 {
143 ATH_MSG_WARNING("evtStore() does not contain hits collection with name " << m_afpToFHitContainerKey);
144 return StatusCode::SUCCESS;
145 }
146
147 ATH_CHECK( afpToFHitContainer.initialize() );
148
150 if ( !afpTrackContainer.isValid() ) {
151 ATH_MSG_WARNING( "evtStore() does not contain hits collection with name " << m_afpTrackContainerKey );
152 return StatusCode::SUCCESS;
153 }
154 ATH_CHECK( afpTrackContainer.initialize() );
155
156 nTofHits = afpToFHitContainer->size();
157 fill("AFPToFTool", lb, nTofHits);
158
159 int eventsInStations[4] = {};
160
161 // hit counts per event for TProfile
162 unsigned int totalHitsPerTrainAll[NSIDES][NTRAINS] = {};
163 unsigned int totalHitsPerTrainFME[NSIDES][NTRAINS][NPOS] = {};
164 unsigned int totalHitsPerBar[NSIDES][NTRAINS][NBARS] = {};
165 unsigned int totalStationHits[NSIDES] = {};
166
167 for(const xAOD::AFPToFHit *hitsItr: *afpToFHitContainer)
168 {
169 if (hitsItr->stationID()<4 && hitsItr->stationID()>=0 && hitsItr->trainID()<4 && hitsItr->trainID()>=0 && hitsItr->barInTrainID()<4 && hitsItr->barInTrainID()>=0)
170 {
171 trainID = hitsItr->trainID();
172 barInTrainID = hitsItr->barInTrainID();
173 ++eventsInStations[hitsItr->stationID()];
174
175 // Only process ToF stations: 0 (farAside) and 3 (farCside)
176 if(hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
177 continue;
178
179 int side = (hitsItr->stationID() == 3) ? 1 : 0;
180 unsigned int train = hitsItr->trainID();
181 unsigned int bar = hitsItr->barInTrainID();
182
183 numberOfHit = train;
184 fill(m_tools[m_SideGroup.at(m_sidesToF.at(side))], numberOfHit);
185
186 barInTrainIDSide = bar;
187 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], barInTrainIDSide);
188
189 barInTrainAll = train * 4 + bar;
190 fill(m_tools[m_SideGroup.at(m_sidesToF.at(side))], barInTrainAll);
191
192 ToFHits_side = eventInfo->lumiBlock();
193 fill(m_tools[m_SideGroup.at(m_sidesToF.at(side))], ToFHits_side, ToFHits_MU_Weight);
194
195 fill(m_tools[m_StationNamesGroup.at(m_stationNamesToF.at(hitsItr->stationID()))], barInTrainID, trainID);
196
197 // per-mu TH1F per-bar
198 lbToFBar = eventInfo->lumiBlock();
199 fill(m_tools[m_BarsInTrains.at(m_sidesToF.at(side)).at(m_trainsToF.at(train)).at(m_barsToF.at(bar))], lbToFBar, lbToFBar_Weight);
200
201 // Accumulate counts for TProfile
202 ++totalStationHits[side];
203 ++totalHitsPerTrainAll[side][train];
204 if(bar < NBARS) ++totalHitsPerBar[side][train][bar];
205 if(position != NPOS) ++totalHitsPerTrainFME[side][train][position];
206
207 // per-mu TH1F: fill per-train
208 lbToFTrainAll = eventInfo->lumiBlock();
209 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFTrainAll, weightToFTrainAll);
210
211 if(position == FRONT)
212 {
213 lbToFTrainFront = eventInfo->lumiBlock();
214 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFTrainFront, weightToFTrainFront);
215 }
216 else if(position == MIDDLE)
217 {
218 lbToFTrainMiddle = eventInfo->lumiBlock();
219 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFTrainMiddle, weightToFTrainMiddle);
220 }
221 else if(position == END)
222 {
223 lbToFTrainEnd = eventInfo->lumiBlock();
224 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFTrainEnd, weightToFTrainEnd);
225 }
226
227 }
228 }
229
230 // Events histograms
231 if(eventsInStations[0] > 0 || eventsInStations[3] > 0)
232 {
233 fill("AFPToFTool", lbAandCToFEvents);
234
235 if(eventsInStations[0] > 0)
236 {
237 fill("AFPToFTool", lbToFEvents[0]);
238 }
239 if(eventsInStations[3] > 0)
240 {
241 fill("AFPToFTool", lbToFEvents[1]);
242 }
243 }
244
245 // per-event TProfile per-train
246 auto lbToFPerEvent = Monitored::Scalar<int>("lbToFPerEvent", eventInfo->lumiBlock());
247 auto hitsPerTrainAllPP = Monitored::Scalar<float>("hitsPerTrainAllPP", 0.0);
248 auto lbToFPerEventFront = Monitored::Scalar<int>("lbToFPerEventFront", eventInfo->lumiBlock());
249 auto hitsPerTrainFrontPP = Monitored::Scalar<float>("hitsPerTrainFrontPP", 0.0);
250 auto lbToFPerEventMiddle = Monitored::Scalar<int>("lbToFPerEventMiddle", eventInfo->lumiBlock());
251 auto hitsPerTrainMiddlePP = Monitored::Scalar<float>("hitsPerTrainMiddlePP", 0.0);
252 auto lbToFPerEventEnd = Monitored::Scalar<int>("lbToFPerEventEnd", eventInfo->lumiBlock());
253 auto hitsPerTrainEndPP = Monitored::Scalar<float>("hitsPerTrainEndPP", 0.0);
254
255 for(unsigned int side = 0; side < NSIDES; side++)
256 {
257 for(unsigned int train = 0; train < NTRAINS; train++)
258 {
259 hitsPerTrainAllPP = totalHitsPerTrainAll[side][train] / muPerBXToF;
260 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFPerEvent, hitsPerTrainAllPP);
261
262 hitsPerTrainFrontPP = totalHitsPerTrainFME[side][train][FRONT] / muPerBXToF;
263 if(position == FRONT)
264 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFPerEventFront, hitsPerTrainFrontPP);
265
266 hitsPerTrainMiddlePP = totalHitsPerTrainFME[side][train][MIDDLE] / muPerBXToF;
267 if(position == MIDDLE)
268 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFPerEventMiddle, hitsPerTrainMiddlePP);
269
270 hitsPerTrainEndPP = totalHitsPerTrainFME[side][train][END] / muPerBXToF;
271 if(position == END)
272 fill(m_tools[m_SideTrainGroup.at(m_sidesToF.at(side)).at(m_trainsToF.at(train))], lbToFPerEventEnd, hitsPerTrainEndPP);
273 }
274 }
275
276 // per-event TProfile per-bar
277 auto lbToFBarPerEvent = Monitored::Scalar<int>("lbToFBarPerEvent", eventInfo->lumiBlock());
278 auto hitsPerBarPP = Monitored::Scalar<float>("hitsPerBarPP", 0.0);
279
280 for(unsigned int side = 0; side < NSIDES; side++)
281 {
282 for(unsigned int train = 0; train < NTRAINS; train++)
283 {
284 for(unsigned int bar = 0; bar < NBARS; bar++)
285 {
286 hitsPerBarPP = totalHitsPerBar[side][train][bar] / muPerBXToF;
287 fill(m_tools[m_BarsInTrains.at(m_sidesToF.at(side)).at(m_trainsToF.at(train)).at(m_barsToF.at(bar))], lbToFBarPerEvent, hitsPerBarPP);
288 }
289 }
290 }
291
292 // per-event TProfile station-level
293 auto lbToFStationPerEvent = Monitored::Scalar<int>("lbToFStationPerEvent", eventInfo->lumiBlock());
294 auto hitsPerStationPP = Monitored::Scalar<float>("hitsPerStationPP", 0.0);
295
296 for(unsigned int side = 0; side < NSIDES; side++)
297 {
298 hitsPerStationPP = totalStationHits[side] / muPerBXToF;
299 fill(m_tools[m_SideGroup.at(m_sidesToF.at(side))], lbToFStationPerEvent, hitsPerStationPP);
300 }
301
302 return fillHistograms_crossBarDeltaT(*afpTrackContainer, *afpToFHitContainer);
303}
304
306 const xAOD::AFPTrackContainer& afpTrackContainer,
307 const xAOD::AFPToFHitContainer& afpToFHitContainer) const {
308 // Initialize monitored variables for histogram filling
309 Monitored::Scalar<float> crossBarDeltaT[2] = {
310 Monitored::Scalar<float>( "crossBarDeltaT_A", 0.0 ),
311 Monitored::Scalar<float>( "crossBarDeltaT_C", 0.0 )
312 };
313
314 bool channel_present[2][16] = {};
315 bool multihit[2] = {};
316 std::size_t track_count[2] = {};
317 std::size_t train_count[2][4] = {};
318
319 for (const xAOD::AFPTrack* tracksItr : afpTrackContainer)
320 {
321 const auto side = tracksItr->stationID() == 3;
322 // Ignore tracks that are not from FAR stations
323 if (tracksItr->stationID() != 0 && tracksItr->stationID() != 3)
324 continue;
325 ++track_count[side];
326 }
327
328 // Load the necessary information
329 auto times = std::vector<std::vector<std::vector<float>>>(2, std::vector<std::vector<float>>(4, std::vector<float>(4, -10000)));
330 for (const xAOD::AFPToFHit* hitsItr : afpToFHitContainer)
331 {
332 const auto side = hitsItr->stationID() == 3;
333 const auto train = hitsItr->trainID();
334 const auto bar = hitsItr->barInTrainID();
335 const auto channel = 4 * train + bar;
336 const auto tof_time = hitsItr->time();
337 const auto TimePs=(tof_time)*1000;
338 //Cut on only 1 SiT track in the monitored station
339 if (track_count[side] != 1) continue;
340 // Ignore hits with an impossible origin
341 if (hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
342 continue;
343 if (train < 0 || train >= 4 || bar < 0 || bar >= 4) continue;
344 if (channel_present[side][channel])
345 multihit[side] = true;
346 channel_present[side][channel] = true;
347 ++train_count[side][train];
348
349 times[side][train][bar]=TimePs;
350
351 }
352
353 for (uint8_t side : {0, 1})
354 {
355 // Cut on only 1 SiT track in the monitored station
356 if (track_count[side] != 1) continue;
357 // Cut on maximum of 1 hit in each ToF channel
358 if (multihit[side]) continue;
359 //Cut on maximum 1 train per event
360 uint8_t multrain[2] = {};
361 for (uint8_t train = 0; train < 4; ++train) {
362 if (train_count[side][train]>1) {
363 ++multrain[side];
364 }
365 }
366 if (multrain[side]>1) continue;
367 //fill histos
368 for (uint8_t train = 0; train < 4; ++train) {
369 for (uint8_t bar1 = 0; bar1 < 4; ++bar1) {
370 for (uint8_t bar2 = 0; bar2 < 4; ++bar2) {
371 if (bar2>bar1) {
372 int comb = bar1*bar2+bar2-1;
373 if (comb==5) {comb=4;}
374 if (comb==8) {comb=5;}
375 int global_comb = train*6 + comb;
376 if (times[side][train][bar1]>-10000 && times[side][train][bar2]>-10000) {
377 crossBarDeltaT[side] = (times[side][train][bar1] - times[side][train][bar2]);
378 fill(m_tools[m_GroupChanCombDeltaT.at(m_chanComb.at(global_comb))], crossBarDeltaT[side]);
379 }
380 }
381 }
382 }
383 }
384 }
385
386 return StatusCode::SUCCESS;
387}
Definitions of AFP stations identification numbers.
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
Property holding a SG store/key/clid from which a ReadHandle is made.
std::vector< std::string > m_barsToF
virtual StatusCode fillHistograms_crossBarDeltaT(const xAOD::AFPTrackContainer &, const xAOD::AFPToFHitContainer &) const
SG::ReadHandleKey< xAOD::AFPToFHitContainer > m_afpToFHitContainerKey
std::vector< std::string > m_trainsToF
std::map< std::string, int > m_GroupChanCombDeltaT
virtual StatusCode initialize() override
initialize
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
std::vector< std::string > m_sidesToF
SG::ReadHandleKey< xAOD::AFPTrackContainer > m_afpTrackContainerKey
std::map< std::string, std::map< std::string, int > > m_SideTrainGroup
std::map< std::string, int > m_SideGroup
std::vector< std::string > m_chanComb
std::vector< std::string > m_stationNamesToF
std::map< std::string, int > m_StationNamesGroup
virtual ~AFPToFAlgorithm()
SG::ReadCondHandleKey< BunchCrossingCondData > m_bunchCrossingKeyToF
std::map< std::string, std::map< std::string, std::map< std::string, int > > > m_BarsInTrains
virtual StatusCode initialize() override
initialize
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.).
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
bool isFilled(const bcid_type bcid) const
The simplest query: Is the bunch crossing filled or not?
Declare a monitored scalar variable.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode initialize(bool used=true)
Verify that the handle has been configured properly.
int lb
Definition globals.cxx:23
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable > > &&variables) const
Fills a vector of variables to a group by reference.
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx) const
Calculate the average mu, i.e.
Generic monitoring tool for athena components.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case).
AFPTrack_v2 AFPTrack
Definition AFPTrack.h:12
AFPToFHitContainer_v1 AFPToFHitContainer
AFPTrackContainer_v2 AFPTrackContainer
AFPToFHit_v1 AFPToFHit
Definition AFPToFHit.h:12