16 constexpr
int reorganizePlanes(
const int station,
const int layer)
18 bool reverse = station == 0 || station == 1;
26 , m_afpHitContainerKey(
"AFPSiHitContainer")
66 numberOfEventsPerLumiblockFront = eventInfo->
lumiBlock();
67 numberOfEventsPerLumiblockMiddle = eventInfo->
lumiBlock();
68 numberOfEventsPerLumiblockEnd = eventInfo->
lumiBlock();
71 const unsigned int bcid = eventInfo->
bcid();
74 ATH_MSG_ERROR(
"Unable to retrieve BunchCrossing conditions object (SiT)" );
79 enum { FRONT, MIDDLE,
END, NPOS } position = NPOS;
80 if(bcData->isFilled(
bcid))
83 fill(
"AFPSiLayerTool", bcidAll);
84 if(!bcData->isFilled(
bcid-1))
88 fill(
"AFPSiLayerTool", bcidFront);
89 fill(
"AFPSiLayerTool", numberOfEventsPerLumiblockFront);
93 if(bcData->isFilled(
bcid+1))
97 fill(
"AFPSiLayerTool", bcidMiddle);
98 fill(
"AFPSiLayerTool", numberOfEventsPerLumiblockMiddle);
104 fill(
"AFPSiLayerTool", bcidEnd);
105 fill(
"AFPSiLayerTool", numberOfEventsPerLumiblockEnd);
151 if (muPerBX == 0.0) {
152 ATH_MSG_DEBUG(
"AverageInteractionsPerCrossing is 0, forcing to 1.0");
155 fill(
"AFPSiLayerTool",
lb, muPerBX);
156 fill(
"AFPSiLayerTool", lbEvents);
160 if(! afpHitContainer.
isValid())
163 return StatusCode::SUCCESS;
171 int eventsInStations[4] = {};
172 int numberOfHitsPerPlane[4][4] = {};
178 lbEventsStations = eventInfo->
lumiBlock();
179 lbEventsStationsAll = eventInfo->
lumiBlock();
180 pixelRowIDChip = hitsItr->pixelRowIDChip();
181 pixelColIDChip = hitsItr->pixelColIDChip();
185 if (hitsItr->stationID()<4 && hitsItr->stationID()>=0 && hitsItr->pixelLayerID()<4 && hitsItr->pixelLayerID()>=0)
187 ++eventsInStations[hitsItr->stationID()];
194 planeHits = hitsItr->pixelLayerID();
197 ++numberOfHitsPerPlane[hitsItr->stationID()][hitsItr->pixelLayerID()];
198 planeHitsAllMU = reorganizePlanes(hitsItr->stationID(), hitsItr->pixelLayerID());
199 weightAllPlanes = 1 / muPerBX;
200 fill(
"AFPSiLayerTool", planeHitsAllMU, weightAllPlanes);
201 weightAllPlanes = 1.0;
203 numberOfHitsPerStation = hitsItr->stationID();
204 fill(
"AFPSiLayerTool", numberOfHitsPerStation);
206 fill(
"AFPSiLayerTool", lbHits);
208 else ATH_MSG_WARNING(
"Unrecognised station index: " << hitsItr->stationID());
214 lbhitsPerPlaneProfile = eventInfo->
lumiBlock();
215 for(
int i_station = 0; i_station < 4; i_station++)
216 for(
int j_layer = 0; j_layer < 4; j_layer++)
218 hitsPerPlaneProfile = numberOfHitsPerPlane[i_station][j_layer]/muPerBX;
223 bool noEventsInStations =
true;
224 for(
int i=0;
i<4;
i++)
226 if(eventsInStations[
i]>0) {
229 eventsPerStation =
i * 4;
230 fill(
"AFPSiLayerTool", eventsPerStation);
232 fill(
"AFPSiLayerTool", eventsPerStation);
234 fill(
"AFPSiLayerTool", eventsPerStation);
236 fill(
"AFPSiLayerTool", eventsPerStation);
238 noEventsInStations =
false;
241 if(!noEventsInStations)
243 fill(
"AFPSiLayerTool", lbEventsStationsAll);
251 unsigned int totalTracksAll[4] = {};
252 unsigned int totalTracksFront[4] = {};
253 unsigned int totalTracksMiddle[4] = {};
254 unsigned int totalTracksEnd[4] = {};
258 trackX =
track.x * 1.0;
259 trackY =
track.y * 1.0;
262 if (position == FRONT)
264 ++totalTracksFront[
track.station];
265 ++totalTracksAll[
track.station];
267 else if (position == MIDDLE)
269 ++totalTracksMiddle[
track.station];
270 ++totalTracksAll[
track.station];
272 else if (position ==
END)
274 ++totalTracksEnd[
track.station];
275 ++totalTracksAll[
track.station];
294 for(
int i = 0;
i < 4;
i++)
296 Total_tracks_All_profile = totalTracksAll[
i] / muPerBX;
298 totalTracksAll[
i] = 0;
300 Total_tracks_Front_profile = totalTracksFront[
i] / muPerBX;
301 if (position == FRONT)
303 totalTracksFront[
i] = 0;
305 Total_tracks_Middle_profile = totalTracksMiddle[
i] / muPerBX;
306 if (position == MIDDLE)
308 totalTracksMiddle[
i] = 0;
310 Total_tracks_End_profile = totalTracksEnd[
i] / muPerBX;
313 totalTracksEnd[
i] = 0;
317 unsigned int totalClustersAll[4][4] = {};
318 unsigned int totalClustersFront[4][4] = {};
319 unsigned int totalClustersMiddle[4][4] = {};
320 unsigned int totalClustersEnd[4][4] = {};
332 lbClustersPerPlanesAll = eventInfo->
lumiBlock();
333 lbClustersPerPlanesFront = eventInfo->
lumiBlock();
334 lbClustersPerPlanesMiddle = eventInfo->
lumiBlock();
335 lbClustersPerPlanesEnd = eventInfo->
lumiBlock();
337 for(
const auto& cluster :
fast.clusters())
339 clusterX = cluster.x * 1.0;
340 clusterY = cluster.y * 1.0;
342 if (cluster.station == 0 || cluster.station == 1)
344 clustersInPlanes = reorganizePlanes(cluster.station, cluster.layer);
348 clustersInPlanes = (cluster.station*4)+cluster.layer;
350 fill(
"AFPSiLayerTool", clustersInPlanes);
352 clusterToT = cluster.sumToT;
355 if (position == FRONT)
357 ++totalClustersFront[cluster.station][cluster.layer];
358 ++totalClustersAll[cluster.station][cluster.layer];
360 else if (position == MIDDLE)
362 ++totalClustersMiddle[cluster.station][cluster.layer];
363 ++totalClustersAll[cluster.station][cluster.layer];
365 else if (position ==
END)
367 ++totalClustersEnd[cluster.station][cluster.layer];
368 ++totalClustersAll[cluster.station][cluster.layer];
372 for(
int i_station = 0; i_station < 4; i_station++)
373 for(
int j_layer = 0; j_layer < 4; j_layer++)
375 clustersPerPlaneAllPP = totalClustersAll[i_station][j_layer] / muPerBX;
377 totalClustersAll[i_station][j_layer] = 0;
379 clustersPerPlaneFrontPP = totalClustersFront[i_station][j_layer] / muPerBX;
380 if (position == FRONT)
382 totalClustersFront[i_station][j_layer] = 0;
384 clustersPerPlaneMiddlePP = totalClustersMiddle[i_station][j_layer] / muPerBX;
385 if (position == MIDDLE)
387 totalClustersMiddle[i_station][j_layer] = 0;
389 clustersPerPlaneEndPP = totalClustersEnd[i_station][j_layer] / muPerBX;
392 totalClustersEnd[i_station][j_layer] = 0;
422 int min_hits[4] = {3, 3, 3, 3};
427 std::vector<std::vector<int>> nclusters_planes(numStations, std::vector<int>(numPlanes, 0));
428 for (
const auto& cluster :
fast.clusters()) {
429 ++nclusters_planes[cluster.station][cluster.layer];
433 std::vector<std::vector<int>> nclusters_other_planes(numStations, std::vector<int>(numPlanes, 0));
434 for (
int iStation = 0; iStation < numStations; ++iStation) {
435 for (
int iPlane = 0; iPlane < numPlanes; ++iPlane) {
436 for (
int ip = 0;
ip < numPlanes; ++
ip) {
437 if (iPlane !=
ip && nclusters_planes[iStation][
ip] > 0) {
438 ++nclusters_other_planes[iStation][iPlane];
445 std::array<std::set<int>, 4> precomputed_tag_planes = {
446 std::set<int>{0, 1, 2, 3},
447 std::set<int>{0, 1, 2, 3},
448 std::set<int>{0, 1, 2, 3},
449 std::set<int>{0, 1, 2, 3}
453 using ClusterType = std::decay_t<decltype(*
fast.clusters().begin())>;
454 std::vector<std::vector<std::vector<ClusterType>>> clusters_by_station_layer(numStations,
455 std::vector<std::vector<ClusterType>>(numPlanes));
457 for (
const auto& cluster :
fast.clusters()) {
458 clusters_by_station_layer[cluster.station][cluster.layer].push_back(cluster);
461 for (
int iStation = 0; iStation < numStations; ++iStation) {
462 for (
int iPlane = 0; iPlane < numPlanes; ++iPlane) {
464 if (nclusters_other_planes[iStation][iPlane] < min_hits[iStation]) {
continue;}
466 std::set<int> tag_planes = precomputed_tag_planes[iStation];
467 tag_planes.erase(iPlane);
469 std::vector<int> v_tag_planes(tag_planes.begin(), tag_planes.end());
470 int seed = v_tag_planes[0];
473 for (
const auto& cluster : clusters_by_station_layer[iStation][seed]) {
474 int found_in_other_tag_planes = 0;
477 for (
size_t i = 1;
i < v_tag_planes.size(); ++
i) {
478 int tag_plane = v_tag_planes[
i];
481 for (
const auto& clusterTag : clusters_by_station_layer[iStation][tag_plane]) {
482 if (std::fabs(cluster.x - clusterTag.x) < 2.0 && std::fabs(cluster.y - clusterTag.y) < 2.0) {
484 ++found_in_other_tag_planes;
493 if (found_in_other_tag_planes ==
static_cast<int>(v_tag_planes.size()) - 1) {
494 sit_plane_eff_triedX = cluster.x;
495 sit_plane_eff_triedY = cluster.y;
498 for (
const auto& clusterTag : clusters_by_station_layer[iStation][iPlane]) {
499 if (std::fabs(cluster.x - clusterTag.x) < 2.0 && std::fabs(cluster.y - clusterTag.y) < 2.0) {
500 sit_plane_eff_passed =
true;
506 sit_plane_eff_passed, sit_plane_eff_triedY, sit_plane_eff_triedX);
507 sit_plane_eff_passed =
false;
512 return StatusCode::SUCCESS;