ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
DerivationFramework::VertexTrackIsolation Class Reference

#include <VertexTrackIsolation.h>

Inheritance diagram for DerivationFramework::VertexTrackIsolation:
Collaboration diagram for DerivationFramework::VertexTrackIsolation:

Public Member Functions

 VertexTrackIsolation (const std::string &t, const std::string &n, const IInterface *p)
 
StatusCode initialize ()
 
StatusCode finalize ()
 
virtual StatusCode addBranches () const
 
bool isSame (const xAOD::Vertex *theVtx1, const xAOD::Vertex *theVtx2) const
 
bool isContainedIn (const xAOD::Vertex *theVtx, const std::vector< const xAOD::Vertex * > &theColl) const
 

Private Attributes

ToolHandle< xAOD::ITrackIsolationToolm_trackIsoTool
 
std::string m_trackContainerName
 
std::string m_vertexContainerName
 
std::vector< unsigned int > m_cones
 
std::vector< std::string > m_passFlags
 
int m_vertexType
 
bool m_doIsoPerTrk
 
int m_removeDuplicate
 
bool m_fixElecExclusion
 
bool m_includeV0
 

Detailed Description

Definition at line 24 of file VertexTrackIsolation.h.

Constructor & Destructor Documentation

◆ VertexTrackIsolation()

DerivationFramework::VertexTrackIsolation::VertexTrackIsolation ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Definition at line 21 of file VertexTrackIsolation.cxx.

22  : base_class(t, n, p),
23  m_trackIsoTool("xAOD::TrackIsolationTool"),
24  m_trackContainerName("InDetTrackParticles"),
25  m_vertexContainerName("NONE"),
26  m_cones(),
27  m_vertexType(7),
28  m_doIsoPerTrk(false),
30  m_fixElecExclusion(false),
31  m_includeV0(false) {
32  ATH_MSG_DEBUG("in constructor");
33 
34  // Declare tools
35  declareProperty("TrackIsoTool", m_trackIsoTool);
36  declareProperty("TrackContainer", m_trackContainerName);
37  declareProperty("InputVertexContainer", m_vertexContainerName);
38  declareProperty("PassFlags", m_passFlags);
39  declareProperty("IsolationTypes", m_cones);
40  declareProperty("DoVertexTypes", m_vertexType);
41 
42  declareProperty("DoIsoPerTrk", m_doIsoPerTrk,
43  "New property to deal with track isolation per track, the default option "
44  "(m_doIsoPerTrk=false) preserves the old behavior");
45  declareProperty("RemoveDuplicate", m_removeDuplicate, "Used with DoIsoPerTrk");
46  declareProperty("FixElecExclusion", m_fixElecExclusion);
47  declareProperty("IncludeV0", m_includeV0);
48 }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::VertexTrackIsolation::addBranches ( ) const
virtual

Definition at line 124 of file VertexTrackIsolation.cxx.

124  {
125 
126  const xAOD::TrackParticleContainer* idTrackParticleContainer = NULL;
127  const xAOD::VertexContainer* vertexContainer = NULL;
128 
129  if (evtStore()->contains<xAOD::TrackParticleContainer>(m_trackContainerName)) {
130  CHECK(evtStore()->retrieve(idTrackParticleContainer, m_trackContainerName));
131  } else {
132  ATH_MSG_ERROR("Failed loading IdTrackparticleContainer container");
133  return StatusCode::FAILURE;
134  }
135 
136  // load vertices
137  if (evtStore()->contains<xAOD::VertexContainer>(m_vertexContainerName)) {
138  CHECK(evtStore()->retrieve(vertexContainer, m_vertexContainerName));
139  } else {
140  ATH_MSG_ERROR("Failed loading vertex container");
141  return StatusCode::FAILURE;
142  }
143 
144  std::vector<const xAOD::Vertex*> outVtxContainer;
145 
146  // Convert m_cones (done per-event to avoid needing extra public dependency)
147 
148  std::vector<xAOD::Iso::IsolationType> cones(m_cones.size());
149 
150  for (unsigned int i = 0; i < m_cones.size(); i++)
151  cones[i] = xAOD::Iso::IsolationType(m_cones[i]);
152 
153  // The provided IsolationTypes are re-ordered internally
154  std::sort(cones.begin(), cones.end(), [](xAOD::Iso::IsolationType i, xAOD::Iso::IsolationType j) {
155  return xAOD::Iso::coneSize(i) > xAOD::Iso::coneSize(j);
156  });
157 
158  // loop over vertices
159  for (auto vertex : *vertexContainer) {
160 
161  bool passed = false;
162  for (std::vector<std::string>::const_iterator flagItr = m_passFlags.begin(); flagItr != m_passFlags.end();
163  ++flagItr) {
164  SG::Accessor<Char_t> flagAcc(*flagItr);
165  if (flagAcc.isAvailable(*vertex) && flagAcc(*vertex) != 0) {
166  passed = true;
167  break;
168  }
169  } // end of loop over flags
170  // if no passFlags given, decorate everything
171  if (passed || m_passFlags.empty()) {
172  if (!m_doIsoPerTrk) { // for legacy
173  // Removed warning was here
174  } else {
175  if (m_removeDuplicate) {
176  if (isContainedIn(vertex, outVtxContainer))
177  continue;
178  outVtxContainer.push_back(vertex);
179  }
180  }
181 
182  TLorentzVector candidate;
183 
184  std::set<const xAOD::TrackParticle*> exclusionset;
185 
186  for (auto part : vertex->trackParticleLinks()) { // Loop over tracks linked to vertex
187 
188  candidate += (*part)->p4();
189 
190  // if you have electron tracks that are GSF, need to get original ID
191  // trackparticle for excluding this particle
192  if (m_fixElecExclusion) {
194  exclusionset.insert(partID);
195  } else
196  exclusionset.insert(*part); // If it crashes use the direct TP from the vertex
197  }
198  // No! the above candidate will fail acceptance of isolation() because
199  // it's neither a muon nor a TrackParticle
200 
201  // Add in V0->XX particles
202  if (m_includeV0) {
204  V0VertexLinksAcc("V0VertexLinks");
205  auto V0VertLink = V0VertexLinksAcc(*vertex);
206  const xAOD::Vertex* V0Vert = V0VertLink.at(0).getDataPtr()->at(0);
207  for (auto part : V0Vert->trackParticleLinks()) {
208  candidate += (*part)->p4();
209  exclusionset.insert(*part);
210  }
211  }
212 
213  // Make a dummy TrackParticle, otherwise TrackIsolationTool cannot deal
214  // with it
215  xAOD::TrackParticle candidate_slyTrack;
216  candidate_slyTrack.makePrivateStore();
217  candidate_slyTrack.setDefiningParameters(0, 0., candidate.Phi(), candidate.Theta(), 0. /*1./candidate.P()*/);
218  // The precision goes down a bit, but it's a matter of 10e-7 with our
219  // values of interest
220 
221  // Make a correctionlist such that the given exclusionset will be removed
222  // from the used tracks There is no danger that the input particle will be
223  // excluded, as it is not part of inDetTrackContainer
224  xAOD::TrackCorrection corrlist;
225  corrlist.trackbitset.set(static_cast<unsigned int>(xAOD::Iso::coreTrackPtr));
226 
227  const string vtxType_name[3] = {"SumPt", "A0", "Z0"};
228 
229  xAOD::BPhysHelper vertex_h(vertex); // Use the BPhysHelper to access vertex quantities
230 
231  // Loop over refitted primary vertex choice
232  for (unsigned int vertex_type = 0; vertex_type <= xAOD::BPhysHelper::PV_MIN_Z0; vertex_type++) {
233 
234  if ((m_vertexType & (1 << vertex_type)) == 0)
235  continue; // Stop if the type of vertex is not required
236 
237  ATH_MSG_DEBUG("List of cone types");
238  for (unsigned int i = 0; i < cones.size(); i++) {
239  ATH_MSG_DEBUG("cone type = " << xAOD::Iso::toString(xAOD::Iso::IsolationType(cones[i])));
240  }
241 
242  const xAOD::Vertex* refVtx = vertex_h.pv(static_cast<xAOD::BPhysHelper::pv_type>(vertex_type)); // Fix the cast
243  if(refVtx == nullptr){
244  ATH_MSG_WARNING("Could not retrieve Vertex type " << vertex_type << ", check vertex type setting. Comes from container " << m_vertexContainerName);
245  continue;
246  }
248 
249  if (!m_doIsoPerTrk) {
250  m_trackIsoTool->trackIsolation(result, candidate_slyTrack, cones, corrlist, refVtx, &exclusionset,
251  idTrackParticleContainer);
252 
253  // Decorate the vertex with all the isolation values
254  for (unsigned int i = 0; i < cones.size(); i++) {
255 
256  string variableName = xAOD::Iso::toString(xAOD::Iso::IsolationType(cones[i]));
257  variableName += vtxType_name[vertex_type];
258 
259  SG::Decorator<float> isolation(variableName);
260  isolation(*vertex) = result.ptcones[i];
261  }
262  } else {
263  for (size_t i = 0; i < vertex->nTrackParticles(); i++) {
264  m_trackIsoTool->trackIsolation(result, *vertex->trackParticle(i), cones, corrlist, refVtx, &exclusionset,
265  idTrackParticleContainer);
266 
267  for (unsigned int j = 0; j < cones.size(); j++) {
268  string variableName = xAOD::Iso::toString(xAOD::Iso::IsolationType(cones[j]));
269  variableName += vtxType_name[vertex_type];
270  variableName += "_trk";
271  variableName += std::to_string(i + 1);
272  SG::Decorator<float> isolation(variableName);
273  isolation(*vertex) = result.ptcones[j];
274  }
275  }
276  }
277  }
278 
279  } // End of if passed
280  } // end of loop over vertices
281 
282  return StatusCode::SUCCESS;
283 }

◆ finalize()

StatusCode DerivationFramework::VertexTrackIsolation::finalize ( )

Definition at line 75 of file VertexTrackIsolation.cxx.

75  {
76  // everything all right
77  return StatusCode::SUCCESS;
78 }

◆ initialize()

StatusCode DerivationFramework::VertexTrackIsolation::initialize ( )

Definition at line 52 of file VertexTrackIsolation.cxx.

52  {
53 
54  ATH_MSG_DEBUG("in initialize()");
55 
56  CHECK(m_trackIsoTool.retrieve());
57  // Check that flags were given to tag the correct vertices
58 
59  // Control the IsolationType sequence
60  if (m_cones.empty()) {
61  ATH_MSG_INFO("Setting ptcones to default");
62 
63  if (m_doIsoPerTrk)
64  m_cones.push_back(xAOD::Iso::ptcone50);
65  m_cones.push_back(xAOD::Iso::ptcone40);
66  m_cones.push_back(xAOD::Iso::ptcone30);
67  m_cones.push_back(xAOD::Iso::ptcone20);
68  }
69 
70  return StatusCode::SUCCESS;
71 }

◆ isContainedIn()

bool DerivationFramework::VertexTrackIsolation::isContainedIn ( const xAOD::Vertex theVtx,
const std::vector< const xAOD::Vertex * > &  theColl 
) const

Definition at line 113 of file VertexTrackIsolation.cxx.

114  {
115  for (const auto vtxPtr : theColl) {
116  if (isSame(vtxPtr, theVtx))
117  return true;
118  }
119  return false;
120 }

◆ isSame()

bool DerivationFramework::VertexTrackIsolation::isSame ( const xAOD::Vertex theVtx1,
const xAOD::Vertex theVtx2 
) const

Definition at line 81 of file VertexTrackIsolation.cxx.

81  {
82  assert(theVtx1);
83  assert(theVtx2);
84  if (theVtx1 == theVtx2)
85  return true;
86  if (theVtx1->nTrackParticles() != theVtx2->nTrackParticles())
87  return false;
88 
89  if (m_removeDuplicate == 2 && theVtx1->nTrackParticles() == 4) { // a special case with sub-structure
90  bool firstTwoAreSame =
91  std::set<const xAOD::TrackParticle*>({theVtx1->trackParticle(0), theVtx1->trackParticle(1)}) ==
92  std::set<const xAOD::TrackParticle*>(
93  {theVtx2->trackParticle(0), theVtx2->trackParticle(1)}); // the 1st pair of tracks
94  bool lastTwoAreSame =
95  std::set<const xAOD::TrackParticle*>({theVtx1->trackParticle(2), theVtx1->trackParticle(3)}) ==
96  std::set<const xAOD::TrackParticle*>(
97  {theVtx2->trackParticle(2), theVtx2->trackParticle(3)}); // the 2nd pair of tracks
98  if (firstTwoAreSame && lastTwoAreSame)
99  return true;
100  else
101  return false;
102  } else { // the general case
103  std::set<const xAOD::TrackParticle*> vtxset1;
104  std::set<const xAOD::TrackParticle*> vtxset2;
105  for (size_t i = 0; i < theVtx1->nTrackParticles(); i++)
106  vtxset1.insert(theVtx1->trackParticle(i));
107  for (size_t i = 0; i < theVtx2->nTrackParticles(); i++)
108  vtxset2.insert(theVtx2->trackParticle(i));
109  return vtxset1 == vtxset2;
110  }
111 }

Member Data Documentation

◆ m_cones

std::vector<unsigned int> DerivationFramework::VertexTrackIsolation::m_cones
private

Definition at line 42 of file VertexTrackIsolation.h.

◆ m_doIsoPerTrk

bool DerivationFramework::VertexTrackIsolation::m_doIsoPerTrk
private

Definition at line 46 of file VertexTrackIsolation.h.

◆ m_fixElecExclusion

bool DerivationFramework::VertexTrackIsolation::m_fixElecExclusion
private

Definition at line 49 of file VertexTrackIsolation.h.

◆ m_includeV0

bool DerivationFramework::VertexTrackIsolation::m_includeV0
private

Definition at line 50 of file VertexTrackIsolation.h.

◆ m_passFlags

std::vector<std::string> DerivationFramework::VertexTrackIsolation::m_passFlags
private

Definition at line 43 of file VertexTrackIsolation.h.

◆ m_removeDuplicate

int DerivationFramework::VertexTrackIsolation::m_removeDuplicate
private

Definition at line 47 of file VertexTrackIsolation.h.

◆ m_trackContainerName

std::string DerivationFramework::VertexTrackIsolation::m_trackContainerName
private

Definition at line 40 of file VertexTrackIsolation.h.

◆ m_trackIsoTool

ToolHandle<xAOD::ITrackIsolationTool> DerivationFramework::VertexTrackIsolation::m_trackIsoTool
private

Definition at line 38 of file VertexTrackIsolation.h.

◆ m_vertexContainerName

std::string DerivationFramework::VertexTrackIsolation::m_vertexContainerName
private

Definition at line 41 of file VertexTrackIsolation.h.

◆ m_vertexType

int DerivationFramework::VertexTrackIsolation::m_vertexType
private

Definition at line 44 of file VertexTrackIsolation.h.


The documentation for this class was generated from the following files:
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DerivationFramework::VertexTrackIsolation::m_trackContainerName
std::string m_trackContainerName
Definition: VertexTrackIsolation.h:40
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
xAOD::BPhysHelper
Definition: BPhysHelper.h:71
xAOD::TrackCorrection
Definition: IsolationCommon.h:18
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
python.CreateTierZeroArgdict.partID
partID
Definition: CreateTierZeroArgdict.py:135
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
xAOD::Iso::toString
std::string toString(const IsoType &iso)
Definition: IsolationHelpers.h:59
xAOD::Iso::coreTrackPtr
@ coreTrackPtr
tracks pointer
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:66
xAOD::Vertex_v1::trackParticleLinks
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
DerivationFramework::VertexTrackIsolation::isContainedIn
bool isContainedIn(const xAOD::Vertex *theVtx, const std::vector< const xAOD::Vertex * > &theColl) const
Definition: VertexTrackIsolation.cxx:113
xAOD::TrackCorrection::trackbitset
Iso::IsolationTrackCorrectionBitset trackbitset
Definition: IsolationCommon.h:19
xAOD::Iso::ptcone30
@ ptcone30
Definition: IsolationType.h:41
xAOD::Iso::ptcone20
@ ptcone20
Track isolation.
Definition: IsolationType.h:40
xAOD::TrackParticle_v1::setDefiningParameters
void setDefiningParameters(float d0, float z0, float phi0, float theta, float qOverP)
Set the defining parameters.
Definition: TrackParticle_v1.cxx:177
DerivationFramework::VertexTrackIsolation::m_cones
std::vector< unsigned int > m_cones
Definition: VertexTrackIsolation.h:42
xAOD::BPhysHelper::PV_MIN_Z0
@ PV_MIN_Z0
Definition: BPhysHelper.h:475
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::VertexTrackIsolation::m_vertexType
int m_vertexType
Definition: VertexTrackIsolation.h:44
DerivationFramework::VertexTrackIsolation::m_trackIsoTool
ToolHandle< xAOD::ITrackIsolationTool > m_trackIsoTool
Definition: VertexTrackIsolation.h:38
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
xAOD::BPhysHelper::pv_type
pv_type
: Enum type of the PV
Definition: BPhysHelper.h:475
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator< float >
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::Iso::IsolationType
IsolationType
Overall enumeration for isolation types in xAOD files.
Definition: IsolationType.h:26
xAOD::Iso::ptcone50
@ ptcone50
Definition: IsolationType.h:43
DerivationFramework::VertexTrackIsolation::m_removeDuplicate
int m_removeDuplicate
Definition: VertexTrackIsolation.h:47
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::Vertex_v1::trackParticle
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Definition: Vertex_v1.cxx:249
DerivationFramework::VertexTrackIsolation::m_fixElecExclusion
bool m_fixElecExclusion
Definition: VertexTrackIsolation.h:49
DerivationFramework::VertexTrackIsolation::m_includeV0
bool m_includeV0
Definition: VertexTrackIsolation.h:50
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DerivationFramework::VertexTrackIsolation::m_passFlags
std::vector< std::string > m_passFlags
Definition: VertexTrackIsolation.h:43
DerivationFramework::VertexTrackIsolation::m_doIsoPerTrk
bool m_doIsoPerTrk
Definition: VertexTrackIsolation.h:46
xAOD::TrackIsolation
Definition: IsolationCommon.h:33
DerivationFramework::VertexTrackIsolation::isSame
bool isSame(const xAOD::Vertex *theVtx1, const xAOD::Vertex *theVtx2) const
Definition: VertexTrackIsolation.cxx:81
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF
const xAOD::TrackParticle * getOriginalTrackParticleFromGSF(const xAOD::TrackParticle *trkPar)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the GSF Track Particle...
Definition: ElectronxAODHelpers.cxx:22
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:192
DerivationFramework::VertexTrackIsolation::m_vertexContainerName
std::string m_vertexContainerName
Definition: VertexTrackIsolation.h:41
xAOD::Iso::ptcone40
@ ptcone40
Definition: IsolationType.h:42
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43