Skip to content
Snippets Groups Projects
Commit 9c7ff802 authored by Christos Anastopoulos's avatar Christos Anastopoulos Committed by Walter Lampl
Browse files

tidy VertexCollectionSortingTool and add explicitly the name of the decoration as configurable

parent 005da049
No related branches found
No related tags found
No related merge requests found
......@@ -12,17 +12,20 @@ def primaryVertexFindingCfg(flags, **kwargs):
else:
vtxFlags = flags.InDet.PriVertex
vertexWeightTool = None
if vtxFlags.sortingSetup == 'SumPt2Sorting':
vertexWeightTool = CompFactory.Trk.SumPtVertexWeightCalculator(
DoSumPt2Selection=True
)
decorName = "sumPt2"
elif vtxFlags.sortingSetup == "SumPtSorting":
vertexWeightTool = CompFactory.Trk.SumPtVertexWeightCalculator(
DoSumPt2Selection=False
)
decorName = "sumPt"
vertexSorter = CompFactory.Trk.VertexCollectionSortingTool(
VertexWeightCalculator=vertexWeightTool,
decorationName=decorName,
)
# finder tool
finderTool = None
......
......@@ -931,18 +931,7 @@ if (InDetFlags.doVertexFinding() or InDetFlags.doVertexFindingForMonitoring()) o
from TrkVertexWeightCalculators.TrkVertexWeightCalculatorsConf import Trk__SumPtVertexWeightCalculator
VertexWeightCalculator = Trk__SumPtVertexWeightCalculator(name = "InDetSumPtVertexWeightCalculator",
DoSumPt2Selection = True)
elif InDetFlags.primaryVertexSortingSetup() == 'VxProbSorting':
from TrkVertexWeightCalculators.TrkVertexWeightCalculatorsConf import Trk__VxProbVertexWeightCalculator
VertexWeightCalculator = Trk__VxProbVertexWeightCalculator(name = "InDetVxProbVertexWeightCalculator",
HistogramPath = "/VxProbHisto/h_sTrkPdfminBias")
elif InDetFlags.primaryVertexSortingSetup() == 'NNSorting':
from TrkVertexWeightCalculators.TrkVertexWeightCalculatorsConf import Trk__NNVertexWeightCalculator
VertexWeightCalculator = Trk__NNVertexWeightCalculator(name = "InDetNNVertexWeightCalculator",
HistoFilePath ="/NNHisto/")
decorName = "sumPt2"
#
ToolSvc += VertexWeightCalculator
if InDetFlags.doPrintConfigurables():
......@@ -953,7 +942,8 @@ if (InDetFlags.doVertexFinding() or InDetFlags.doVertexFindingForMonitoring()) o
#
from TrkVertexTools.TrkVertexToolsConf import Trk__VertexCollectionSortingTool
VertexCollectionSortingTool = Trk__VertexCollectionSortingTool(name = "InDetVertexCollectionSortingTool",
VertexWeightCalculator = VertexWeightCalculator)
VertexWeightCalculator = VertexWeightCalculator,
decorationName=decorName)
ToolSvc += VertexCollectionSortingTool
if InDetFlags.doPrintConfigurables():
printfunc (VertexCollectionSortingTool)
......
......@@ -2,67 +2,73 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TrkVertexTools_VertexCollectionSortingTool_H
#define TrkVertexTools_VertexCollectionSortingTool_H
#ifndef TrkVertexTools_VertexCollectionSortingTool_H
#define TrkVertexTools_VertexCollectionSortingTool_H
#include "TrkVertexFitterInterfaces/IVertexCollectionSortingTool.h"
#include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h"
///
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ToolHandle.h"
#include "TrkVertexFitterInterfaces/IVertexCollectionSortingTool.h"
//xAOD include
#include "xAODTracking/VertexFwd.h"
// xAOD include
#include "xAODTracking/TrackParticleAuxContainer.h"
#include "xAODTracking/TrackParticleContainerFwd.h"
#include "xAODTracking/TrackParticleFwd.h"
#include "xAODTracking/VertexContainerFwd.h"
#include "xAODTracking/VertexAuxContainer.h"
#include "xAODTracking/TrackParticleContainerFwd.h"
#include "xAODTracking/TrackParticleAuxContainer.h"
#include "xAODTracking/VertexContainerFwd.h"
#include "xAODTracking/VertexFwd.h"
/**
* @class Trk::VertexCollectionSortingTool
*
* @author Johanna Bronner, April 2009
*
* --------------------------------------
* Changes:
*
* David Shope <david.richard.shope@cern.ch> (2016-04-26)
*
* EDM Migration to xAOD - remove method using VxCandidate
*/
namespace Trk {
class IVertexWeightCalculator;
class VertexCollectionSortingTool final
: public AthAlgTool
, virtual public IVertexCollectionSortingTool
{
public:
virtual StatusCode initialize() override;
virtual StatusCode finalize() override;
/**
* constructor
*/
VertexCollectionSortingTool(const std::string& t,
const std::string& n,
const IInterface* p);
/**
* destructor
*/
virtual ~VertexCollectionSortingTool() = default;
/** Sort **/
virtual std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
sortVertexContainer(const xAOD::VertexContainer& MyVxCont) const override;
/**
* @class Trk::VertexCollectionSortingTool
*
* @author Johanna Bronner, April 2009
*
* --------------------------------------
* Changes:
*
* David Shope <david.richard.shope@cern.ch> (2016-04-26)
*
* EDM Migration to xAOD - remove method using VxCandidate
*/
namespace Trk
{
class IVertexWeightCalculator;
class VertexCollectionSortingTool : public AthAlgTool, virtual public IVertexCollectionSortingTool
{
public:
virtual StatusCode initialize() override;
virtual StatusCode finalize() override;
/**
* constructor
*/
VertexCollectionSortingTool(const std::string& t, const std::string& n, const IInterface* p);
/**
* destructor
*/
virtual ~VertexCollectionSortingTool();
/** Sort **/
virtual std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
sortVertexContainer(const xAOD::VertexContainer& MyVxCont) const override;
private:
ToolHandle<Trk::IVertexWeightCalculator> m_iVertexWeightCalculator{
this,
"VertexWeightCalculator",
"Trk::IVertexWeightCalculator"
};
Gaudi::Property<std::string> m_decorationName{
this,
"decorationName",
"sumPt2",
"Name to use for the decoration"
};
private:
ToolHandle < Trk::IVertexWeightCalculator> m_iVertexWeightCalculator;
}; // end of class description
} // end of namespace definition
}; //end of class description
}//end of namespace definition
#endif
#endif
......@@ -3,114 +3,110 @@
*/
#include "TrkVertexTools/VertexCollectionSortingTool.h"
#include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h"
#include "VxVertex/VxTrackAtVertex.h"
#include <vector>
#include <vector>
namespace {
struct Vertex_pair
{
double first;
const xAOD::Vertex* second;
Vertex_pair(double p1, const xAOD::Vertex* p2)
: first (p1), second (p2) {}
bool operator< (const Vertex_pair& other) const
{ return first > other.first; }
};
struct Vertex_pair
{
double first;
const xAOD::Vertex* second;
Vertex_pair(double p1, const xAOD::Vertex* p2)
: first(p1)
, second(p2)
{}
bool operator<(const Vertex_pair& other) const { return first > other.first; }
};
} // anonymous namespace
namespace Trk {
// constructor
VertexCollectionSortingTool::VertexCollectionSortingTool(const std::string& t,
const std::string& n,
const IInterface* p)
: AthAlgTool(t, n, p)
{
declareInterface<IVertexCollectionSortingTool>(this);
}
// initialize
StatusCode
VertexCollectionSortingTool::initialize()
{
if (m_iVertexWeightCalculator.retrieve().isFailure()) {
ATH_MSG_FATAL("Failed to retrieve tool " << m_iVertexWeightCalculator);
return StatusCode::FAILURE;
}
namespace Trk{
//constructor
VertexCollectionSortingTool::VertexCollectionSortingTool ( const std::string& t, const std::string& n, const IInterface* p )
: AthAlgTool ( t,n,p ),
m_iVertexWeightCalculator("Trk::IVertexWeightCalculator")
{
declareInterface<IVertexCollectionSortingTool> ( this );
declareProperty ( "VertexWeightCalculator",m_iVertexWeightCalculator);
ATH_MSG_INFO("Initialization successful");
return StatusCode::SUCCESS;
} /// EndOfInitialize
StatusCode
VertexCollectionSortingTool::finalize()
{
return StatusCode::SUCCESS;
}
std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
VertexCollectionSortingTool::sortVertexContainer(
const xAOD::VertexContainer& MyVxCont) const
{
std::vector<Vertex_pair> MyVertex_pairs;
xAOD::VertexContainer::const_iterator beginIter = MyVxCont.begin();
xAOD::VertexContainer::const_iterator endIter = MyVxCont.end();
for (xAOD::VertexContainer::const_iterator i = beginIter; i != endIter; ++i) {
// do not weight dummy!!! (do not delete it either! it is deleted when the
// original MyVxContainer is deleted in InDetPriVxFinder.cxx)
if ((*i)->vertexType() != xAOD::VxType::NoVtx) {
double Weight =
m_iVertexWeightCalculator->estimateSignalCompatibility(**i);
MyVertex_pairs.emplace_back(Weight, (*i));
ATH_MSG_DEBUG("Weight before sorting: " << Weight);
}
}
//destructor
VertexCollectionSortingTool::~VertexCollectionSortingTool()= default;
//initialize
StatusCode VertexCollectionSortingTool::initialize()
{
if ( m_iVertexWeightCalculator.retrieve().isFailure() )
{
msg(MSG::FATAL) << "Failed to retrieve tool " << m_iVertexWeightCalculator << endmsg;
return StatusCode::FAILURE;
if (!MyVertex_pairs.empty()) {
std::sort(MyVertex_pairs.begin(), MyVertex_pairs.end());
}
xAOD::VertexContainer* NewContainer = new xAOD::VertexContainer();
xAOD::VertexAuxContainer* auxNewContainer = new xAOD::VertexAuxContainer();
NewContainer->setStore(auxNewContainer);
SG::AuxElement::Accessor<float> sigWeightDec(m_decorationName);
unsigned int vtxCount(1);
for (std::vector<Vertex_pair>::const_iterator iter = MyVertex_pairs.begin();
iter != MyVertex_pairs.end();
++iter) {
ATH_MSG_DEBUG("Weight after sorting: " << (*iter).first);
xAOD::Vertex* vxCand = new xAOD::Vertex(
*(iter->second)); // use copy-constructor, creates a private store
NewContainer->push_back(
vxCand); // private store is now copied to the container store
if (vtxCount == 1) {
vxCand->setVertexType(xAOD::VxType::PriVtx);
} else {
vxCand->setVertexType(xAOD::VxType::PileUp);
}
msg(MSG::INFO) << "Initialization successful" << endmsg;
return StatusCode::SUCCESS;
}///EndOfInitialize
StatusCode VertexCollectionSortingTool::finalize()
{
return StatusCode::SUCCESS;
sigWeightDec(*vxCand) = iter->first;
vtxCount++;
}
std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
VertexCollectionSortingTool::sortVertexContainer(
const xAOD::VertexContainer& MyVxCont) const
{
std::vector<Vertex_pair> MyVertex_pairs;
xAOD::VertexContainer::const_iterator beginIter = MyVxCont.begin();
xAOD::VertexContainer::const_iterator endIter = MyVxCont.end();
for(xAOD::VertexContainer::const_iterator i = beginIter; i!=endIter; ++i)
{
// do not weight dummy!!! (do not delete it either! it is deleted when the original MyVxContainer is deleted in InDetPriVxFinder.cxx)
if ((*i)->vertexType() != xAOD::VxType::NoVtx)
{
double Weight =m_iVertexWeightCalculator->estimateSignalCompatibility(**i);
MyVertex_pairs.emplace_back(Weight,(*i));
ATH_MSG_DEBUG("Weight before sorting: " << Weight);
}
}
if (!MyVertex_pairs.empty())
{
std::sort (MyVertex_pairs.begin(), MyVertex_pairs.end());
}
xAOD::VertexContainer *NewContainer = new xAOD::VertexContainer();
xAOD::VertexAuxContainer* auxNewContainer = new xAOD::VertexAuxContainer();
NewContainer->setStore( auxNewContainer );
std::string decorationName = (m_iVertexWeightCalculator->name().find("InDetSumPtVertexWeightCalculator") != std::string::npos) ? "sumPt2" : "signalCompatibility";
SG::AuxElement::Accessor< float > sigWeightDec(decorationName);
unsigned int vtxCount(1);
for (std::vector<Vertex_pair>::const_iterator iter = MyVertex_pairs.begin() ; iter != MyVertex_pairs.end(); ++iter )
{
ATH_MSG_DEBUG("Weight after sorting: " << (*iter).first);
xAOD::Vertex* vxCand = new xAOD::Vertex(*(iter->second)); //use copy-constructor, creates a private store
NewContainer->push_back(vxCand); //private store is now copied to the container store
if (vtxCount == 1) {
vxCand->setVertexType(xAOD::VxType::PriVtx);
} else {
vxCand->setVertexType(xAOD::VxType::PileUp);
}
sigWeightDec(*vxCand) = iter->first;
vtxCount++;
}
// add dummy at position of first vertex
xAOD::Vertex* primaryVtx = NewContainer->front();
xAOD::Vertex* dummyVxCandidate = new xAOD::Vertex();
NewContainer->push_back ( dummyVxCandidate );
dummyVxCandidate->setPosition(primaryVtx->position());
dummyVxCandidate->setCovariancePosition(primaryVtx->covariancePosition());
dummyVxCandidate->setVertexType(xAOD::VxType::NoVtx);
return std::make_pair(NewContainer, auxNewContainer);
}
}///End!!!
// add dummy at position of first vertex
xAOD::Vertex* primaryVtx = NewContainer->front();
xAOD::Vertex* dummyVxCandidate = new xAOD::Vertex();
NewContainer->push_back(dummyVxCandidate);
dummyVxCandidate->setPosition(primaryVtx->position());
dummyVxCandidate->setCovariancePosition(primaryVtx->covariancePosition());
dummyVxCandidate->setVertexType(xAOD::VxType::NoVtx);
return std::make_pair(NewContainer, auxNewContainer);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment