ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
RecoTools
ParticlesInConeTools
src
IParticlesLookUpTable.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef PARTICLESINCONETOOLS_IPARTICLELOOKUPTABLE_H
6
#define PARTICLESINCONETOOLS_IPARTICLELOOKUPTABLE_H
7
8
#include <limits>
9
#include <cmath>
10
#include "
AthContainers/DataVector.h
"
11
12
namespace
xAOD
{
13
14
16
template
<
class
T>
17
class
IParticlesLookUpTable
{
18
public
:
20
IParticlesLookUpTable
(
unsigned
int
nbins = 50 ,
float
minPt=1
e
-3) :
m_container
(0),
21
m_nphiBins
(nbins),
22
m_phiBinSize
(
m_2PI
/
m_nphiBins
),
23
m_minPt
(minPt),
24
m_phiBinnedLookUpTable
()
25
{}
26
28
void
init
(
const
DataVector<T>
& particles );
29
31
void
clear
();
32
34
template
<
class
O>
35
bool
iParticlesInCone
(
float
eta
,
float
phi
,
float
dr, O& output )
const
;
36
38
bool
isInitialized
()
const
;
39
40
private
:
42
static
constexpr
float
m_2PI
= 2*
M_PI
;
43
45
float
phiInRange
(
float
phi
)
const
{
46
while
(
phi
>=
M_PI
)
phi
-=
m_2PI
;
47
while
(
phi
< -
M_PI
)
phi
+=
m_2PI
;
48
return
phi
;
49
}
50
52
int
phiIndex
(
float
phi
)
const
{
return
(
phi
+
M_PI
)/
m_phiBinSize
; };
53
55
void
addEntry
(
int
i, std::vector< const T* >& output )
const
;
56
58
void
addEntry
(
int
i, std::vector<
ElementLink
<
DataVector<T>
> >& output )
const
;
59
60
61
const
DataVector<T>
*
m_container
;
//internal container
62
int
m_nphiBins
;
63
float
m_phiBinSize
;
64
float
m_minPt
;
65
std::vector< std::vector< int > >
m_phiBinnedLookUpTable
;
66
};
67
68
template
<
class
T>
69
bool
IParticlesLookUpTable<T>::isInitialized
()
const
{
return
!
m_phiBinnedLookUpTable
.empty(); }
70
71
72
template
<
class
T>
73
void
IParticlesLookUpTable<T>::clear
() {
74
m_phiBinnedLookUpTable
.clear();
75
}
76
77
template
<
class
T>
78
void
IParticlesLookUpTable<T>::init
(
const
DataVector<T>
& particles ) {
80
m_phiBinnedLookUpTable
.resize(
m_nphiBins
);
81
m_container
= &particles;
84
unsigned
int
size
= particles.size();
85
for
(
unsigned
int
i=0; i<
size
;++i ){
86
if
(particles[i]->
pt
()>
m_minPt
){
//sanity check (mainly due to Truth)
87
int
index
=
phiIndex
(particles[i]->
phi
());
88
m_phiBinnedLookUpTable
[
index
].push_back(i);
89
}
90
}
91
//std::cout << " initializing lookup " << m_container->size() << std::endl;
92
for
(
auto
&
vec
:
m_phiBinnedLookUpTable
) {
93
if
(
vec
.empty() )
continue
;
94
std::stable_sort
(
vec
.begin(),
vec
.end(),[&](
int
i,
int
j) { return (*m_container)[i]->eta() < (*m_container)[j]->eta(); });
95
// std::cout << " new phi slice " << vec.size() << " eta " ;
96
// for( auto index : vec ){
97
// std::cout << " " << (*m_container)[index]->eta();
98
// }
99
// std::cout << std::endl;
100
}
101
}
102
103
template
<
class
T>
template
<
class
O>
104
bool
IParticlesLookUpTable<T>::iParticlesInCone
(
float
eta
,
float
phi
,
float
dr, O& output )
const
{
105
107
if
(
m_phiBinnedLookUpTable
.empty() )
return
false
;
108
110
auto
compEta1 = [&](
int
i,
double
val ) {
return
(*
m_container
)[i]->eta() < val; };
111
auto
compEta2 = [&](
double
val,
int
i ) {
return
val < (*m_container)[i]->eta(); };
112
114
int
indexMin =
phiIndex
(
phiInRange
(
phi
-dr) );
115
int
indexMax =
phiIndex
(
phiInRange
(
phi
+dr) );
116
//std::cout << " eta " << eta << " phi " << phi << " phi ranges " << indexMin << " " << indexMax << std::endl;
117
// special treatment for boundary region
118
std::vector< std::pair<int,int> > ranges;
119
if
( indexMin > indexMax ) {
120
ranges.push_back( std::make_pair(0,indexMax) );
121
ranges.push_back( std::make_pair(indexMin,
m_nphiBins
-1) );
122
}
else
{
123
ranges.push_back( std::make_pair(indexMin,indexMax) );
124
}
125
126
float
dr2Cut = dr*dr;
127
128
// loop over ranges
129
for
(
auto
& range : ranges ){
130
indexMin = range.first;
131
indexMax = range.second;
132
for
( ; indexMin <= indexMax; ++indexMin ){
133
// get iterators for iparticles to be included
134
const
std::vector< int >& tps =
m_phiBinnedLookUpTable
[indexMin];
135
auto
it_min = std::lower_bound (tps.begin(),tps.end(),
eta
-dr,compEta1 );
136
auto
it_max = std::upper_bound (it_min,tps.end(),
eta
+dr,compEta2 );
137
//std::cout << " new range, entries in bounds " << std::distance(it_max,it_min) << std::endl;
138
// add iparticles in cone
139
for
( ;it_min!=it_max;++it_min ){
140
const
T* entry = (*m_container)[*it_min];
141
float
deta =
eta
- entry->eta();
142
float
dphi =
phiInRange
(
phi
-entry->phi());
143
float
dr2 = deta*deta + dphi*dphi;
144
//std::cout << " new entry: " << *it_min << " eta,phi " << entry->eta() << " phi " << entry->phi() << " dr " << sqrt(dr2) << std::endl;
145
if
( dr2 < dr2Cut )
addEntry
( *it_min, output );
146
}
147
}
148
}
149
return
true
;
150
}
151
152
template
<
class
T>
153
void
IParticlesLookUpTable<T>::addEntry
(
int
i, std::vector< const T* >& output )
const
{
154
output.push_back( (*
m_container
)[i]);
155
}
156
157
template
<
class
T>
158
void
IParticlesLookUpTable<T>::addEntry
(
int
i, std::vector<
ElementLink
<
DataVector<T>
> >& output )
const
{
159
output.push_back(
ElementLink
<
DataVector<T>
>(*
m_container
,i) );
160
}
161
162
}
// end of namespace
163
164
#endif
165
166
M_PI
#define M_PI
Definition
ActiveFraction.h:14
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
vec
std::vector< size_t > vec
Definition
CombinationsGeneratorTest.cxx:9
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
size
size_t size() const
Number of registered mappings.
DataVector
Derived DataVector<T>.
Definition
DataVector.h:795
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
xAOD::IParticlesLookUpTable::addEntry
void addEntry(int i, std::vector< ElementLink< DataVector< T > > > &output) const
add an entry into a vector of ElementLinks
Definition
IParticlesLookUpTable.h:158
xAOD::IParticlesLookUpTable< CaloCluster >::m_container
const DataVector< CaloCluster > * m_container
Definition
IParticlesLookUpTable.h:61
xAOD::IParticlesLookUpTable::phiInRange
float phiInRange(float phi) const
hepler function to ensure phi is within +-Pi
Definition
IParticlesLookUpTable.h:45
xAOD::IParticlesLookUpTable::iParticlesInCone
bool iParticlesInCone(float eta, float phi, float dr, O &output) const
collect IParticles in a given cone
Definition
IParticlesLookUpTable.h:104
xAOD::IParticlesLookUpTable< CaloCluster >::m_phiBinSize
float m_phiBinSize
Definition
IParticlesLookUpTable.h:63
xAOD::IParticlesLookUpTable::addEntry
void addEntry(int i, std::vector< const T * > &output) const
add an entry into a vector of pointers
Definition
IParticlesLookUpTable.h:153
xAOD::IParticlesLookUpTable< CaloCluster >::m_minPt
float m_minPt
Definition
IParticlesLookUpTable.h:64
xAOD::IParticlesLookUpTable::isInitialized
bool isInitialized() const
return whether table is initialized
Definition
IParticlesLookUpTable.h:69
xAOD::IParticlesLookUpTable< CaloCluster >::m_2PI
static constexpr float m_2PI
Definition
IParticlesLookUpTable.h:42
xAOD::IParticlesLookUpTable< CaloCluster >::m_nphiBins
int m_nphiBins
Definition
IParticlesLookUpTable.h:62
xAOD::IParticlesLookUpTable::phiIndex
int phiIndex(float phi) const
calculate phi index for a given phi
Definition
IParticlesLookUpTable.h:52
xAOD::IParticlesLookUpTable::IParticlesLookUpTable
IParticlesLookUpTable(unsigned int nbins=50, float minPt=1e-3)
constructor taking the desired binsize
Definition
IParticlesLookUpTable.h:20
xAOD::IParticlesLookUpTable::init
void init(const DataVector< T > &particles)
initialize the look up table with an iParticle container
Definition
IParticlesLookUpTable.h:78
xAOD::IParticlesLookUpTable< CaloCluster >::m_phiBinnedLookUpTable
std::vector< std::vector< int > > m_phiBinnedLookUpTable
Definition
IParticlesLookUpTable.h:65
xAOD::IParticlesLookUpTable::clear
void clear()
clear the look up table
Definition
IParticlesLookUpTable.h:73
index
Definition
index.py:1
std::stable_sort
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
Definition
DVL_algorithms.h:644
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition
ICaloAffectedTool.h:24
xAOD::pt
setRcore setEtHad setFside pt
Definition
TrigPhoton_v1.cxx:106
xAOD::e
setPy e
Definition
CompositeParticle_v1.cxx:166
xAOD::phi
setEt phi
Definition
TrigEMCluster_v1.cxx:29
Generated on
for ATLAS Offline Software by
1.17.0