ATLAS Offline Software
Loading...
Searching...
No Matches
TauShotVariableHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef XAOD_ANALYSIS
6
8
16
18
19ANA_MSG_SOURCE(msgTauShotVariableHelpers, "TauShotVariableHelpers")
20
21
24 const CaloCell_ID* calo_id,
25 const LArNeighbours::neighbourOption& option) {
26 const CaloCell* neigCell = nullptr;
27
28 std::vector<IdentifierHash> neighHashes;
29 calo_id->get_neighbours(cell->caloDDE()->calo_hash(), option, neighHashes);
30
31 // Loop all the cells, and find the required neighbour cell
32 for (const auto cell : links) {
33 const IdentifierHash& cellHash = cell->caloDDE()->calo_hash();
34
35 // Check whether the cell is a neighbour cell
36 for (const IdentifierHash& neighHash : neighHashes) {
37 if (cellHash == neighHash) {
38 neigCell = cell;
39 return neigCell;
40 }
41 }
42 }
43
44 return neigCell;
45}
46
47
48std::vector<std::vector<const CaloCell*> > getCellBlock(const xAOD::PFO& shot, const CaloCell_ID* calo_id) {
49 using namespace TauShotVariableHelpers::msgTauShotVariableHelpers;
50
51 std::vector<std::vector<const CaloCell*>> cellBlock;
52
53 int etaSize = 0;
54 if (shot.attribute(xAOD::PFODetails::PFOAttributes::tauShots_nCellsInEta, etaSize) == false) {
55 ANA_MSG_WARNING("Couldn't find nCellsInEta. Return empty cell block.");
56 return cellBlock;
57 }
58
59 int seedHash = 0;
60 if (shot.attribute(xAOD::PFODetails::PFOAttributes::tauShots_seedHash, seedHash) == false) {
61 ANA_MSG_WARNING("Couldn't find seed hash. Return empty cell block.");
62 return cellBlock;
63 }
64
65 // Initialize the cell block
66 std::vector<const CaloCell*> etaLayer;
67 for (int etaIndex = 0; etaIndex < etaSize; ++ etaIndex) {
68 etaLayer.push_back(nullptr);
69 }
70 int phiSize = 2;
71 for (int phiIndex = 0; phiIndex < phiSize; ++phiIndex) {
72 cellBlock.push_back(etaLayer);
73 }
74
75 // Get seed cell from shot cluster
76 const xAOD::CaloCluster* cluster = shot.cluster(0);
77 const CaloClusterCellLink* cellLinks = cluster->getCellLinks();
78
79 const CaloCell* seedCell = nullptr;
80 for (const auto cell : *cellLinks) {
81 if (cell->caloDDE()->calo_hash() != (unsigned) seedHash) continue;
82 seedCell = cell;
83 break;
84 }
85 if (seedCell==nullptr) {
86 ANA_MSG_WARNING("Couldn't find seed cell in shot cluster. Return empty cell block.");
87 return cellBlock;
88 }
89 int mediumEtaIndex = etaSize/2;
90 cellBlock.at(0).at(mediumEtaIndex) = seedCell;
91
92 // Obtain the neighbour cells in the eta direction
93 // -- Next in eta
94 const CaloCell* lastCell = seedCell;
95 int maxDepth = etaSize - mediumEtaIndex - 1;
96 for (int depth = 1; depth < maxDepth + 1; ++depth) {
97 lastCell = getNeighbour(lastCell, *cellLinks, calo_id, LArNeighbours::nextInEta);
98 if (lastCell != nullptr) {
99 cellBlock.at(0).at(mediumEtaIndex + depth) = lastCell;
100 }
101 else {
102 break;
103 }
104 }
105
106 // -- Previous in eta
107 lastCell = seedCell;
108 for (int depth = 1; depth < maxDepth + 1; ++depth) {
109 lastCell = getNeighbour(lastCell, *cellLinks, calo_id, LArNeighbours::prevInEta);
110 if (lastCell != nullptr) {
111 cellBlock.at(0).at(mediumEtaIndex - depth) = lastCell;
112 }
113 else {
114 break;
115 }
116 }
117
118 // Merged cell
119 const CaloCell* mergedCell = getNeighbour(seedCell, *cellLinks, calo_id, LArNeighbours::nextInPhi);
120 if (mergedCell == nullptr) {
121 mergedCell = getNeighbour(seedCell, *cellLinks, calo_id, LArNeighbours::prevInPhi);
122 }
123
124 if (mergedCell != nullptr) {
125 cellBlock.at(1).at(mediumEtaIndex) = mergedCell;
126
127 // Obtain the neighbour cells in the eta direction
128 // -- Next in eta
129 lastCell = mergedCell;
130 for (int depth = 1; depth < maxDepth + 1; ++depth) {
131 lastCell = getNeighbour(lastCell, *cellLinks, calo_id, LArNeighbours::nextInEta);
132 if (lastCell != nullptr) {
133 cellBlock.at(1).at(mediumEtaIndex + depth) = lastCell;
134 }
135 else {
136 break;
137 }
138 }
139
140 // -- Previous in eta
141 lastCell = mergedCell;
142 for (int depth = 1; depth < maxDepth + 1; ++depth) {
143 lastCell = getNeighbour(lastCell, *cellLinks, calo_id, LArNeighbours::prevInEta);
144 if (lastCell != nullptr) {
145 cellBlock.at(1).at(mediumEtaIndex - depth) = lastCell;
146 }
147 else {
148 break;
149 }
150 }
151 } // End of mergedCell != nullptr
152
153 return cellBlock;
154}
155
156
157
158float ptWindow(const std::vector<std::vector<const CaloCell*>>& shotCells,
159 int windowSize,
160 const ToolHandle<IHadronicCalibrationTool>& caloWeightTool) {
161 // window size should be odd and smaller than eta window of shotCells
162 if (windowSize%2 != 1) return 0.;
163
164 int etaSize = shotCells.at(0).size();
165 if (windowSize > etaSize) return 0.;
166
167 int seedIndex = etaSize/2;
168 int phiSize = shotCells.size();
169
170 float ptWindow = 0.;
171 for (int etaIndex = 0; etaIndex != etaSize; ++etaIndex) {
172 if (std::abs(etaIndex-seedIndex) > windowSize/2) continue;
173
174 for (int phiIndex = 0; phiIndex != phiSize; ++phiIndex) {
175 const CaloCell* cell = shotCells.at(phiIndex).at(etaIndex);
176 if (cell != nullptr) {
177 ptWindow += cell->pt() * caloWeightTool->wtCell(cell);
178 }
179 }
180 }
181
182 return ptWindow;
183}
184
185} // End of namespace TauShotVariableHelpers
186
187#endif
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
This is a "hash" representation of an Identifier.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
bool attribute(PFODetails::PFOAttributes AttributeType, T &anAttribute) const
get a PFO Variable via enum
const CaloCluster * cluster(unsigned int index) const
Retrieve a const pointer to a CaloCluster.
Definition PFO_v1.cxx:669
std::string depth
tag string for intendation
Definition fastadd.cxx:46
implementation of photon shot variable calculation
std::vector< std::vector< const CaloCell * > > getCellBlock(const xAOD::PFO &shot, const CaloCell_ID *calo_id)
Get cell block with (currently) 2 x 5 cells in correct order for variable calculations.
const CaloCell * getNeighbour(const CaloCell *cell, const CaloClusterCellLink &links, const CaloCell_ID *calo_id, const LArNeighbours::neighbourOption &option)
Obtain the required neighbour cell.
float ptWindow(const std::vector< std::vector< const CaloCell * > > &shotCells, int windowSize, const ToolHandle< IHadronicCalibrationTool > &caloWeightTool)
pt in a window of (currently) 2 x windowSize cells
PFO_v1 PFO
Definition of the current "pfo version".
Definition PFO.h:17
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.