11#include <boost/container/static_vector.hpp>
66 const float errConst = -9999999.;
76 const std::vector<const xAOD::Vertex*> &PVlist,
77 const size_t PV_minNTracks)
const {
80 lowZ=std::numeric_limits<std::size_t>::max();
83 size_t size = PVlist.size();
85 for(
size_t i =1; i<
size; i++) {
86 if ( PVlist[i]->nTrackParticles() >= PV_minNTracks ) {
88 if(a0z < lowA0zcalc) {
98 const std::vector<const xAOD::Vertex*> &PVlist,
99 const size_t PV_minNTracks)
const {
102 lowA0=std::numeric_limits<std::size_t>::max();
105 size_t size = PVlist.size();
107 for(
size_t i =1; i<
size; i++) {
108 if ( PVlist[i]->nTrackParticles() >= PV_minNTracks ) {
123 std::vector<const xAOD::Vertex*> goodPrimaryVertices;
124 goodPrimaryVertices.reserve(pvContainer->
size());
126 for (
auto ptr = pvContainer->
begin(); ptr!= pvContainer->
end(); ++ptr) {
127 VertexType thistype = (*ptr)->vertexType();
128 if ( thistype == Pileupvtx || thistype == Pvtx ) {
129 goodPrimaryVertices.push_back(*ptr);
134 return goodPrimaryVertices;
148 static const Amg::Vector3D defaultBS(-10000.,-10000.,-10000.);
155 const std::vector<const xAOD::Vertex*> &PVlist,
156 const size_t PV_minNTracks)
const {
158 size_t ilowZ0BA = std::numeric_limits<std::size_t>::max();
159 double lowZ0BAcalc = std::numeric_limits<double>::max();
160 for (
size_t i = 0; i<PVlist.size(); ++i) {
161 if ( PVlist[i]->nTrackParticles() >= PV_minNTracks ) {
163 if (z0BA < lowZ0BAcalc) {
185 TLorentzVector totalMom;
186 unsigned int NTrk = mom.size();
187 for(
unsigned int it=0; it<NTrk; it++) totalMom += mom[it];
188 TVector3 totP = totalMom.Vect();
191 if ( pT.mag2() > 0 ) {
195 xDOCA = xSV - pSV*pT.dot(xT)/pT.mag2();
197 std::cout <<
"BPhysPVCascadeTools::DocaExtrapToBeamSpot: WARNING pT == 0."
205 auto &collection = result->vertices();
206 for(
auto v : collection)
208 std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
209 for(
unsigned int i=0; i< v->trackParticleLinks().
size(); i++)
213 newLinkVector.push_back( mylink );
216 v->setTrackParticleLinks( newLinkVector );
222 auto &collection = result->vertices();
223 for(
auto v : collection) {
224 std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
225 for(
auto mylink : v->trackParticleLinks()) {
228 for(
auto col : trackCols){
229 if(std::find(col->begin(), col->end(), myptr) != col->end()){
234 if(foundcontainer ==
nullptr){
235 throw std::runtime_error(
"Could not find track in original containers");
237 mylink.setStorableObject(*foundcontainer,
true);
238 newLinkVector.push_back( mylink );
241 v->setTrackParticleLinks( newLinkVector );
247 std::vector<const xAOD::TrackParticle*> exclTrk;
248 for(
size_t jt=0; jt<cascadeVertices.size(); jt++) {
249 for(
size_t it=0; it<cascadeVertices[jt]->vxTrackAtVertex().
size(); it++) {
250 if(cascadeVertices[jt]->trackParticle(it)->
charge() != 0) exclTrk.push_back(cascadeVertices[jt]->trackParticle(it));
267 const std::vector<xAOD::Vertex*> &cascadeVertices = casc->
vertices();
268 const bool doPt = (DoVertexType & 1) != 0;
269 const bool doA0 = (DoVertexType & 2) != 0;
270 const bool doZ0 = (DoVertexType & 4) != 0;
271 const bool doZ0BA = (DoVertexType & 8) != 0;
277 const std::vector<const xAOD::Vertex*> GoodPVs =
GetGoodPV(pvContainer);
279 if (GoodPVs.empty() ==
false) {
281 size_t pVmax =std::min((
size_t)in_PV_max, GoodPVs.size());
282 std::vector<const xAOD::Vertex*> refPVvertexes;
283 std::vector<xAOD::Vertex*> refPVvertexes_toDelete;
284 std::vector<int> exitCode;
285 refPVvertexes.reserve(pVmax);
286 refPVvertexes_toDelete.reserve(pVmax);
287 exitCode.reserve(pVmax);
291 for (
size_t i =0; i < pVmax ; i++) {
298 exitCode.push_back(exitcode);
300 if (refPV ==
nullptr) {
301 refPVvertexes.push_back(oldPV);
302 refPVvertexes_toDelete.push_back(
nullptr);
304 refPVvertexes.push_back(refPV);
305 refPVvertexes_toDelete.push_back(refPV);
308 boost::container::static_vector<size_t, 4> indexesUsed;
309 boost::container::static_vector<std::pair<size_t, xAOD::BPhysHelper::pv_type>, 4> indexestoProcess;
312 indexestoProcess.push_back(std::make_pair
325 if( lowZBA < pVmax ) {
331 for(
size_t i =0 ; i<indexestoProcess.size(); i++){
333 auto index = indexestoProcess[i].first;
334 auto pvtype = indexestoProcess[i].second;
336 (refPVvertexes_toDelete.at(
index)) ? refPvContainer : pvContainer;
337 if(ParentContainer == refPvContainer && std::find(indexesUsed.begin(),
338 indexesUsed.end(),
index) == indexesUsed.
end()) {
341 indexesUsed.push_back(
index);
344 ParentContainer, pvtype, exitCode[
index]);
349 for(
size_t x : indexesUsed) refPVvertexes_toDelete[
x] =
nullptr;
352 for(
const xAOD::Vertex* ptr : refPVvertexes_toDelete)
delete ptr;
353 refPVvertexes.clear();
354 refPVvertexes_toDelete.clear();
376 if ( lowZBA < GoodPVs.size() ) {
386 if(pvContainer->
empty())
return StatusCode::FAILURE;
418 return StatusCode::SUCCESS;
425 const std::vector< std::vector<TLorentzVector> > &moms = casc->
getParticleMoms();
426 const std::vector<xAOD::Vertex*> &cascadeVertices = casc->
vertices();
428 std::vector<float> px;
429 std::vector<float> py;
430 std::vector<float> pz;
431 for(
size_t jt=0; jt<moms.size(); jt++) {
432 for(
size_t it=0; it<cascadeVertices[jt]->vxTrackAtVertex().
size(); it++) {
433 px.push_back( moms[jt][it].Px() );
434 py.push_back( moms[jt][it].Py() );
435 pz.push_back( moms[jt][it].Pz() );
438 vtx.
setRefTrks(std::move(px),std::move(py),std::move(pz));
444 if(std::count(col.begin(), col.end(), p) > 1)
return false;
451 if((std::count(col1.begin(), col1.end(), p) + std::count(col2.begin(), col2.end(), p)) > 1)
return false;
454 if((std::count(col1.begin(), col1.end(), p) + std::count(col2.begin(), col2.end(), p)) > 1)
return false;
465 auto precedingVerticesItr = vertices.begin();
466 for(; precedingVerticesItr!=vertices.end(); ++precedingVerticesItr) {
468 if( !(*precedingVerticesItr) )
481 precedingVertexLinks.push_back( vertexLink );
486 decor(*vert) = precedingVertexLinks;
double charge(const T &p)
: B-physics xAOD helpers.
#define BPHYS_CHECK(EXP)
Useful CHECK macro.
std::vector< size_t > vec
size_t size() const
Number of registered mappings.
xAOD::Vertex * refitVertex(const xAOD::Vertex *vertex, const xAOD::Vertex *excludeVertex, bool ReturnCopy=true, int *exitcode=nullptr) const
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
ElementLink implementation for ROOT usage.
bool setElement(ElementType element)
Set link to point to an Element (slowest).
bool isValid() const
Check if the element can be found.
bool setStorableObject(BaseConstReference data, bool replace=false)
Set link storable to data object pointed by data (slower).
const std::vector< Amg::MatrixX > & getCovariance() const
const std::vector< std::vector< TLorentzVector > > & getParticleMoms() const
const std::vector< xAOD::Vertex * > & vertices() const
float setZ0(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
longitudinal impact parameter
bool setLxyErr(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
its error
bool setLxy(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the transverse decay distance and its error measured between the refitted primary vertex of type ...
float setZ0Err(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
longitudinal impact parameter error
const xAOD::Vertex * vtx() const
Getter method for the cached xAOD::Vertex.
float setA0(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the 3D and transverse impact parameters and their error.
bool setPv(const xAOD::Vertex *pv, const xAOD::VertexContainer *vertexContainer, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the refitted collision vertex of type pv_type.
const xAOD::Vertex * pv(const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Get the refitted collision vertex of type pv_type.
pv_type
: Enum type of the PV
bool setRefTrks(std::vector< float > px, std::vector< float > py, std::vector< float > pz)
Sets refitted track momenta.
float setA0Err(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
3D impact parameter error
bool setRefitPVStatus(int code, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the exitCode of the refitter for vertex of type pv_type.
float setA0xyErr(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
transverse impact parameter error
float setA0xy(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
transverse impact parameter
bool setOrigPv(const xAOD::Vertex *pv, const xAOD::VertexContainer *vertexContainer, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the original collision vertex of type pv_type.
bool setTau(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0, const tau_type tauType=BPhysHypoHelper::TAU_CONST_MASS)
: Set the proper decay time and error.
bool setTauErr(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0, const tau_type tauType=BPhysHypoHelper::TAU_CONST_MASS)
proper decay time error
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 3, 1 > Vector3D
EventInfo_v1 EventInfo
Definition of the latest event info version.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".