ATLAS Offline Software
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 
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;
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());
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();
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());
254  }
255 
257  struct Extractor {
258  Trk::TrackParametersIdHelper parsIdHelper;
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;
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());
286  }
287 
288 }
289 #endif
get_generator_info.result
result
Definition: get_generator_info.py:21
CaloExtensionHelpers::midPointEtaPhiPerLayerVector
void midPointEtaPhiPerLayerVector(const Trk::CaloExtension &extension, EtaPhiPerLayerVector &result, const LayersToSelect *selection=nullptr)
Definition: CaloExtensionHelpers.h:273
CaloExtensionHelpers::midPointEtaPhiHashLookupVector
void midPointEtaPhiHashLookupVector(const Trk::CaloExtension &extension, EtaPhiHashLookupVector &result)
Definition: CaloExtensionHelpers.h:256
CaloExtensionHelpers::ScalarLayerMap
std::map< CaloSampling::CaloSample, double > ScalarLayerMap
Definition: CaloExtensionHelpers.h:22
CaloExtensionHelpers::MidPointsHashLookupVector
std::vector< std::pair< bool, Amg::Vector3D > > MidPointsHashLookupVector
Definition: CaloExtensionHelpers.h:19
Trk::CaloExtension
Tracking class to hold the extrapolation from a particle from the ID to the muon system (or the other...
Definition: CaloExtension.h:18
beamspotman.cur
def cur
Definition: beamspotman.py:671
CaloExtensionHelpers::entryEtaPhiPerLayerVector
void entryEtaPhiPerLayerVector(const Trk::CaloExtension &extension, EtaPhiPerLayerVector &result, const LayersToSelect *selection=nullptr)
Definition: CaloExtensionHelpers.h:242
CaloExtension.h
CaloExtensionHelpers::entryExitLayerMap
void entryExitLayerMap(const Trk::CaloExtension &extension, EntryExitLayerMap &result, const LayersToSelect *selection=nullptr)
Definition: CaloExtensionHelpers.h:192
Trk::TrackParametersIdHelper::caloSample
CaloSampling::CaloSample caloSample(TrackParametersIdentifier id) const
CaloSample encoded in id, returns CaloSampling::Unknown if id is not valid
Definition: TrackParametersIdHelper.h:91
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
Trk::TrackParametersIdHelper::isEntryToVolume
bool isEntryToVolume(TrackParametersIdentifier id) const
returns true if the id belongs to the volume entrance
Definition: TrackParametersIdHelper.h:81
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
GeoPrimitives.h
Trk::TrackParametersIdHelper
helper class to encode and decode a TrackParametersIdentifier
Definition: TrackParametersIdHelper.h:18
TrackParametersIdHelper.h
CaloExtensionHelpers::EtaPhiHashLookupVector
std::vector< std::tuple< bool, double, double > > EtaPhiHashLookupVector
Definition: CaloExtensionHelpers.h:24
CaloExtensionHelpers::EtaPhiPerLayerVector
std::vector< std::tuple< CaloSampling::CaloSample, double, double > > EtaPhiPerLayerVector
Definition: CaloExtensionHelpers.h:25
Trk::CurvilinearParametersT
Definition: CurvilinearParametersT.h:48
CaloExtensionHelpers::EntryExitPerLayerVector
std::vector< std::tuple< CaloSampling::CaloSample, Amg::Vector3D, Amg::Vector3D > > EntryExitPerLayerVector
Definition: CaloExtensionHelpers.h:20
CaloExtensionHelpers::EntryExitLayerMap
std::map< CaloSampling::CaloSample, std::pair< Amg::Vector3D, Amg::Vector3D > > EntryExitLayerMap
Definition: CaloExtensionHelpers.h:21
calibdata.exit
exit
Definition: calibdata.py:236
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
CaloExtensionHelpers::midPointsHashLookupVector
void midPointsHashLookupVector(const Trk::CaloExtension &extension, MidPointsHashLookupVector &result)
Definition: CaloExtensionHelpers.h:159
selection
const std::string selection
Definition: fbtTestBasics.cxx:74
CaloExtensionHelpers::pathLenLayerMap
void pathLenLayerMap(const Trk::CaloExtension &extension, ScalarLayerMap &result)
Definition: CaloExtensionHelpers.h:205
CaloExtensionHelpers::eLossLayerMap
void eLossLayerMap(const Trk::CaloExtension &extension, ScalarLayerMap &result)
Definition: CaloExtensionHelpers.h:216
CaloSampling::getNumberOfSamplings
static constexpr unsigned int getNumberOfSamplings()
Get number of available samplings.
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:30
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
CaloExtensionHelpers::entryExitPerLayerVector
void entryExitPerLayerVector(const Trk::CaloExtension &extension, EntryExitPerLayerVector &result, const LayersToSelect *selection=nullptr)
Definition: CaloExtensionHelpers.h:178
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CaloExtensionHelpers::entryEtaPhiHashLookupVector
void entryEtaPhiHashLookupVector(const Trk::CaloExtension &extension, EtaPhiHashLookupVector &result)
Definition: CaloExtensionHelpers.h:227
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
Trk::CaloExtension::caloLayerIntersections
const std::vector< CurvilinearParameters > & caloLayerIntersections() const
access to the intersections with the calorimeter layers.
Definition: CaloExtension.h:76
CaloExtensionHelpers::entryExitProcessor
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
Definition: CaloExtensionHelpers.h:137
tools.zlumi_alleff.extract
def extract(histogram, bin1, bin2)
Definition: zlumi_alleff.py:272
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:26
CaloExtensionHelpers::LayersToSelect
std::set< CaloSampling::CaloSample > LayersToSelect
Definition: CaloExtensionHelpers.h:27
CaloExtensionHelpers
Definition: CaloExtensionHelpers.h:17