ATLAS Offline Software
Loading...
Searching...
No Matches
CaloExtensionHelpers.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef CALOEXTENSIONHELPERS_H
6#define CALOEXTENSIONHELPERS_H
7
11
12#include <vector>
13#include <map>
14#include <iostream>
15#include <set>
16
18
19 typedef std::vector< std::pair<bool,Amg::Vector3D> > MidPointsHashLookupVector;
20 typedef std::vector< std::tuple<CaloSampling::CaloSample, Amg::Vector3D, Amg::Vector3D> > EntryExitPerLayerVector;
21 typedef std::map< CaloSampling::CaloSample, std::pair<Amg::Vector3D, Amg::Vector3D> > EntryExitLayerMap;
22 typedef std::map< CaloSampling::CaloSample, double > ScalarLayerMap;
23
24 typedef std::vector< std::tuple<bool, double, double> > EtaPhiHashLookupVector;
25 typedef std::vector< std::tuple<CaloSampling::CaloSample, double, double> > EtaPhiPerLayerVector;
26
27 typedef std::set<CaloSampling::CaloSample> LayersToSelect;
28
134
135
136 template< class T, class O>
137 inline void entryExitProcessor( const Trk::CaloExtension& extension,
138 T& result, O oper,
139 const LayersToSelect* selection = nullptr ){
140
141 Trk::TrackParametersIdHelper parsIdHelper;
142 // loop over calo layers, keep track of previous layer
143 auto cur = extension.caloLayerIntersections().begin();
144 auto prev = cur;
145 for( ; cur != extension.caloLayerIntersections().end() ; ++cur ){
146 // check that prev and cur are not the same, if not fill if the previous was an entry layer
147 if( prev != cur && parsIdHelper.isEntryToVolume((*prev).cIdentifier()) ) {
148
149 // apply selection
150 if( !selection || selection->count(parsIdHelper.caloSample((*prev).cIdentifier())) ){
151 oper(result,*prev,*cur);
152 }
153 }
154 prev=cur;
155 }
156 }
157
158 // returns a per sampling the mid point of the crossed layers and a boolean indicating whether the layer was crossed
160
161 // create output vector
162 struct Extractor {
163 Trk::TrackParametersIdHelper parsIdHelper;
164 void operator()(MidPointsHashLookupVector& vec,
166 auto& val = vec[parsIdHelper.caloSample(entry.cIdentifier())];
167 val.first = true;
168 val.second = 0.5*( exit.position() + entry.position() );
169 //std::cout << " adding mid point, sampling " << parsIdHelper.caloSample(entry.cIdentifier()) << std::endl;
170 }
171 } extract;
172 result.clear();
173 result.resize(CaloSampling::getNumberOfSamplings(),std::make_pair(false,Amg::Vector3D()));
174 entryExitProcessor(extension,result,extract);
175 }
176
177
178 inline void entryExitPerLayerVector( const Trk::CaloExtension& extension,
180 const LayersToSelect* selection = nullptr ) {
181 struct Extractor {
182 Trk::TrackParametersIdHelper parsIdHelper;
183 void operator()(EntryExitPerLayerVector& vec, const Trk::CurvilinearParameters& entry,const Trk::CurvilinearParameters& exit ){
184 vec.push_back( std::make_tuple(parsIdHelper.caloSample(entry.cIdentifier()),entry.position(),exit.position()) );
185 }
186 } extract;
187 result.clear();
188 result.reserve(extension.caloLayerIntersections().size());
189 entryExitProcessor(extension,result,extract,selection);
190 }
191
192 inline void entryExitLayerMap( const Trk::CaloExtension& extension,
194 const LayersToSelect* selection = nullptr ) {
195 struct Extractor {
196 Trk::TrackParametersIdHelper parsIdHelper;
197 void operator()(EntryExitLayerMap& thisResult, const Trk::CurvilinearParameters& entry,const Trk::CurvilinearParameters& exit ){
198 thisResult[ parsIdHelper.caloSample(entry.cIdentifier()) ] = std::make_pair(entry.position(),exit.position());
199 }
200 } extract;
201 result.clear();
202 entryExitProcessor(extension,result,extract,selection);
203 }
204
205 inline void pathLenLayerMap( const Trk::CaloExtension& extension, ScalarLayerMap& result ) {
206 struct Extractor {
207 Trk::TrackParametersIdHelper parsIdHelper;
208 void operator()(ScalarLayerMap& thisResult, const Trk::CurvilinearParameters& entry,const Trk::CurvilinearParameters& exit ){
209 thisResult[ parsIdHelper.caloSample(entry.cIdentifier()) ] = (entry.position()-exit.position()).mag();
210 }
211 } extract;
212 result.clear();
213 entryExitProcessor(extension,result,extract);
214 }
215
216 inline void eLossLayerMap( const Trk::CaloExtension& extension, ScalarLayerMap& result ) {
217 struct Extractor {
218 Trk::TrackParametersIdHelper parsIdHelper;
219 void operator()(ScalarLayerMap& thisResult, const Trk::CurvilinearParameters& entry,const Trk::CurvilinearParameters& exit ){
220 thisResult[ parsIdHelper.caloSample(entry.cIdentifier()) ] = fabs(entry.momentum().mag()-exit.momentum().mag());
221 }
222 } extract;
223 result.clear();
224 entryExitProcessor(extension,result,extract);
225 }
226
228 struct Extractor {
229 Trk::TrackParametersIdHelper parsIdHelper;
231 auto& val = vec[parsIdHelper.caloSample(entry.cIdentifier())];
232 std::get<0>(val) = true;
233 std::get<1>(val) = entry.position().eta();
234 std::get<2>(val) = entry.position().phi();
235 }
236 } extract;
237 result.clear();
238 result.resize(CaloSampling::getNumberOfSamplings(),std::make_tuple(false,0.,0.));
239 entryExitProcessor(extension,result,extract);
240 }
241
242 inline void entryEtaPhiPerLayerVector( const Trk::CaloExtension& extension,
244 const LayersToSelect* selection = nullptr ) {
245 struct Extractor {
246 Trk::TrackParametersIdHelper parsIdHelper;
248 vec.push_back( std::make_tuple(parsIdHelper.caloSample(entry.cIdentifier()),entry.position().eta(),entry.position().phi()) );
249 }
250 } extract;
251 result.clear();
252 result.reserve(extension.caloLayerIntersections().size());
253 entryExitProcessor(extension,result,extract,selection);
254 }
255
257 struct Extractor {
258 Trk::TrackParametersIdHelper parsIdHelper;
259 void operator()(EtaPhiHashLookupVector& vec, const Trk::CurvilinearParameters& entry,const Trk::CurvilinearParameters& exit ){
260 auto& val = vec[parsIdHelper.caloSample(entry.cIdentifier())];
261 Amg::Vector3D pos = 0.5*( exit.position() + entry.position() );
262 std::get<0>(val) = true;
263 std::get<1>(val) = pos.eta();
264 std::get<2>(val) = pos.phi();
265 //std::cout << " adding sampling " << parsIdHelper.caloSample(entry.cIdentifier()) << " eta " << std::get<1>(val) << " phi " << std::get<2>(val) << std::endl;
266 }
267 } extract;
268 result.clear();
269 result.resize(CaloSampling::getNumberOfSamplings(),std::make_tuple(false,0.,0.));
270 entryExitProcessor(extension,result,extract);
271 }
272
273 inline void midPointEtaPhiPerLayerVector( const Trk::CaloExtension& extension,
275 const LayersToSelect* selection = nullptr ) {
276 struct Extractor {
277 Trk::TrackParametersIdHelper parsIdHelper;
278 void operator()(EtaPhiPerLayerVector& vec, const Trk::CurvilinearParameters& entry,const Trk::CurvilinearParameters& exit ){
279 Amg::Vector3D pos = 0.5*( exit.position() + entry.position() );
280 vec.push_back( std::make_tuple(parsIdHelper.caloSample(entry.cIdentifier()),pos.eta(),pos.phi()) );
281 }
282 } extract;
283 result.clear();
284 result.reserve(extension.caloLayerIntersections().size());
285 entryExitProcessor(extension,result,extract,selection);
286 }
287
288}
289#endif
std::vector< size_t > vec
static constexpr unsigned int getNumberOfSamplings()
Get number of available samplings.
Tracking class to hold the extrapolation through calorimeter Layers Both the caloEntryLayerIntersecti...
const std::vector< CurvilinearParameters > & caloLayerIntersections() const
access to the intersections with the calorimeter layers.
helper class to encode and decode a TrackParametersIdentifier
bool isEntryToVolume(TrackParametersIdentifier id) const
returns true if the id belongs to the volume entrance
CaloSampling::CaloSample caloSample(TrackParametersIdentifier id) const
CaloSample encoded in id, returns CaloSampling::Unknown if id is not valid.
const std::string selection
Eigen::Matrix< double, 3, 1 > Vector3D
void entryEtaPhiHashLookupVector(const Trk::CaloExtension &extension, EtaPhiHashLookupVector &result)
std::set< CaloSampling::CaloSample > LayersToSelect
void entryExitPerLayerVector(const Trk::CaloExtension &extension, EntryExitPerLayerVector &result, const LayersToSelect *selection=nullptr)
void midPointsHashLookupVector(const Trk::CaloExtension &extension, MidPointsHashLookupVector &result)
void entryExitLayerMap(const Trk::CaloExtension &extension, EntryExitLayerMap &result, const LayersToSelect *selection=nullptr)
std::map< CaloSampling::CaloSample, double > ScalarLayerMap
void pathLenLayerMap(const Trk::CaloExtension &extension, ScalarLayerMap &result)
std::vector< std::pair< bool, Amg::Vector3D > > MidPointsHashLookupVector
void eLossLayerMap(const Trk::CaloExtension &extension, ScalarLayerMap &result)
void entryEtaPhiPerLayerVector(const Trk::CaloExtension &extension, EtaPhiPerLayerVector &result, const LayersToSelect *selection=nullptr)
void entryExitProcessor(const Trk::CaloExtension &extension, T &result, O oper, const LayersToSelect *selection=nullptr)
the header provides a set of helper functions to extract per layer information from the CaloExtension
std::vector< std::tuple< CaloSampling::CaloSample, Amg::Vector3D, Amg::Vector3D > > EntryExitPerLayerVector
void midPointEtaPhiPerLayerVector(const Trk::CaloExtension &extension, EtaPhiPerLayerVector &result, const LayersToSelect *selection=nullptr)
std::map< CaloSampling::CaloSample, std::pair< Amg::Vector3D, Amg::Vector3D > > EntryExitLayerMap
std::vector< std::tuple< bool, double, double > > EtaPhiHashLookupVector
void midPointEtaPhiHashLookupVector(const Trk::CaloExtension &extension, EtaPhiHashLookupVector &result)
std::vector< std::tuple< CaloSampling::CaloSample, double, double > > EtaPhiPerLayerVector
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters