ATLAS Offline Software
Loading...
Searching...
No Matches
JpsiUpsilonCommon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "TLorentzVector.h"
10
11namespace Analysis {
12 // *********************************************************************************
13
14 // ---------------------------------------------------------------------------------
15 // getPt: returns the pT of a track pair
16 // ---------------------------------------------------------------------------------
17 double JpsiUpsilonCommon::getPt(std::span<const xAOD::TrackParticle* const> tracks)
18 {
19 if (tracks.empty()) {
20 return 0.0;
21 }
22
23 // Start with the four-momentum of the first track
24 auto momentum = tracks[0]->genvecP4();
25
26 // Add the rest
27 for (size_t i = 1; i < tracks.size(); ++i) {
28 momentum += tracks[i]->genvecP4();
29 }
30
31 return std::sqrt(momentum.Perp2());
32 }
33
34 double JpsiUpsilonCommon::getInvariantMass(const xAOD::TrackParticle* trk1, double mass1, const xAOD::TrackParticle* trk2, double mass2)
35 {
36 auto mom1 = trk1->genvecP4();
37 mom1.SetM(mass1);
38 auto mom2 = trk2->genvecP4();
39 mom2.SetM(mass2);
40 return (mom1 + mom2).M();
41 }
42
43 double JpsiUpsilonCommon::getInvariantMass(std::span<const xAOD::TrackParticle*> tracks,
44 std::span<const double> masses)
45 {
46 assert(tracks.size() == masses.size());
47 // Start with the four-momentum of the first track
48 auto Totalmomentum = tracks[0]->genvecP4();
49 Totalmomentum.SetM(masses[0]);
50
51 for (size_t i = 1; i < tracks.size(); ++i) {
52 auto momentum = tracks[i]->genvecP4();
53 momentum.SetM(masses[i]);
54 Totalmomentum += momentum;
55 }
56 return Totalmomentum.M();
57 }
58
59
60 // -------------------------------------------------------------------------------------------------
61 // isContainedIn: boolean function which checks if a track (1st argument) is also contained in a
62 // vector (second argument)
63 // -------------------------------------------------------------------------------------------------
64
65 bool JpsiUpsilonCommon::isContainedIn(const xAOD::TrackParticle* theTrack, std::span<const xAOD::TrackParticle* const> theColl) noexcept {
66 return std::find(theColl.begin(), theColl.end(), theTrack) != theColl.end();
67 }
68
70 bool isContained(false);
72 for (muItr=theColl->begin(); muItr!=theColl->end(); ++muItr) {
73 auto& link = ( *muItr )->inDetTrackParticleLink();
74 if ( link.isValid() && ( *link == theTrack ) ) {isContained=true; break;}
75 }
76 return isContained;
77 }
78
79 bool JpsiUpsilonCommon::cutRange(double value, double min, double max) noexcept {
80 return (min<=0.0 || value >= min) && (max <= 0.0 || value <= max);
81 }
82
83 bool JpsiUpsilonCommon::cutRangeOR(std::span<double const> values, double min, double max) noexcept {
84 for(double m : values) {
85 if( (min<=0.0 || m >= min) && (max <= 0.0 || m <= max)) return true;
86 }
87 return false;
88 }
89
90 bool JpsiUpsilonCommon::cutAcceptGreater(double value, double min ) noexcept {
91 return (min <=0.0 || value >= min);
92 }
93
94 bool JpsiUpsilonCommon::cutAcceptGreaterOR(std::span<double const> values, double min) noexcept {
95 for(double m : values) {
96 if(min <=0.0 || m >= min) return true;
97 }
98 return false;
99 }
100
102 const xAOD::VertexContainer* importedPVerticesCollection,
103 const Analysis::PrimaryVertexRefitter *pvRefitter){
104 const xAOD::Vertex* vtx_closest = nullptr; // vertex closest to bVertex track
105 if(importedPVerticesCollection->empty()) return Analysis::CleanUpVertex(nullptr, false);
106 double dc = 1e10;
107 std::vector<const xAOD::Vertex*> tocleanup;
108 if(pvRefitter) tocleanup.reserve(importedPVerticesCollection->size());
109 bool vertexrefitted = false;
110 for (const xAOD::Vertex* PV : *importedPVerticesCollection) {
111 const xAOD::Vertex* refPV = pvRefitter ? pvRefitter->refitVertex(PV, bHelper.vtx(), false) : nullptr;
112 const xAOD::Vertex* vtx = refPV ? refPV : PV;
113 if(refPV) tocleanup.push_back(refPV);
114 TVector3 posPV(vtx->position().x(),vtx->position().y(),vtx->position().z());
115 auto &helperpos = bHelper.vtx()->position();
116 TVector3 posV(helperpos.x(), helperpos.y(), helperpos.z());
117 TVector3 nV = bHelper.totalP().Unit();
118 TVector3 dposV = posPV-posV;
119 double dposVnV = dposV*nV;
120 double d = std::sqrt(std::abs(dposV.Mag2()-dposVnV*dposVnV));
121 if (d<dc) {
122 dc = d;
123 vtx_closest = vtx;
124 vertexrefitted = (vtx_closest == refPV);
125 }
126 }
127 for(auto ptr : tocleanup){
128 if(ptr != vtx_closest) delete ptr;
129 }
130 return Analysis::CleanUpVertex(vtx_closest, vertexrefitted);
131 }
132
133 void JpsiUpsilonCommon::RelinkVertexTracks(std::span<const xAOD::TrackParticleContainer* const> trkcols, xAOD::Vertex* vtx) {
134 std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
135 auto size = vtx->trackParticleLinks().size();
136 for(size_t i = 0; i<size; i++){
137 const xAOD::TrackParticle* mylink= *(vtx->trackParticleLinks()[i]);
138 for(const xAOD::TrackParticleContainer* trkcol : trkcols){
139 auto itr = std::find(trkcol->begin(), trkcol->end(), mylink);
140 if(itr != trkcol->end()){
141 auto mylink=vtx->trackParticleLinks()[i];
142 mylink.setStorableObject(*trkcol, true);
143 newLinkVector.push_back( mylink );
144 break;
145 }
146 }
147 }
148 if(size != newLinkVector.size()){
149 throw std::runtime_error("JpsiUpsilonCommon::RelinkVertexTracks: Could not relink all tracks");
150 }
151 vtx->clearTracks();
152 vtx->setTrackParticleLinks( newLinkVector );
153 }
154
155 void JpsiUpsilonCommon::RelinkVertexMuons(std::span<const xAOD::MuonContainer* const> muoncols, xAOD::Vertex* vtx){
157 using MuonLinkVector = std::vector<MuonLink>;
158 static const SG::AuxElement::Decorator<MuonLinkVector> muonLinksDecor("MuonLinks");
159 const MuonLinkVector &mlinksold = muonLinksDecor(*vtx);
160 auto size = mlinksold.size();
161 MuonLinkVector newmulinks;
162 for(size_t i = 0; i<size; i++){
163 const xAOD::Muon* mylink= *(mlinksold[i]);
164 for(const xAOD::MuonContainer* mucol : muoncols){
165 auto itr = std::find(mucol->begin(), mucol->end(), mylink);
166 if(itr != mucol->end()){
167 auto mylink=mlinksold[i];
168 mylink.setStorableObject(*mucol, true);
169 newmulinks.push_back( mylink );
170 break;
171 }
172 }
173 }
174 if(size != newmulinks.size()){
175 throw std::runtime_error("JpsiUpsilonCommon::RelinkVertexMuons: Could not relink all tracks");
176 }
177 muonLinksDecor(*vtx) = std::move(newmulinks);
178 }
179}
180
std::vector< MuonLink > MuonLinkVector
ElementLink< xAOD::MuonContainer > MuonLink
: B-physics xAOD helpers.
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
static bool cutRange(double value, double min, double max) noexcept
static void RelinkVertexMuons(std::span< const xAOD::MuonContainer *const > muoncols, xAOD::Vertex *vtx)
static double getInvariantMass(const xAOD::TrackParticle *trk1, double mass1, const xAOD::TrackParticle *trk2, double mass2)
static void RelinkVertexTracks(std::span< const xAOD::TrackParticleContainer *const > trkcols, xAOD::Vertex *vtx)
static bool cutAcceptGreaterOR(std::span< double const > values, double min) noexcept
static Analysis::CleanUpVertex ClosestRefPV(xAOD::BPhysHelper &, const xAOD::VertexContainer *, const Analysis::PrimaryVertexRefitter *)
static bool cutRangeOR(std::span< double const > values, double min, double max) noexcept
static bool isContainedIn(const xAOD::TrackParticle *, std::span< const xAOD::TrackParticle *const >) noexcept
static double getPt(std::span< const xAOD::TrackParticle *const > tracks)
static bool cutAcceptGreater(double value, double min) noexcept
xAOD::Vertex * refitVertex(const xAOD::Vertex *vertex, const xAOD::Vertex *excludeVertex, bool ReturnCopy=true, int *exitcode=nullptr) const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
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.
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:576
const xAOD::Vertex * vtx() const
Getter method for the cached xAOD::Vertex.
TVector3 totalP()
: Returns total 3-momentum calculated from the refitted tracks
GenVecFourMom_t genvecP4() const
The full 4-momentum of the particle : GenVector form.
void setTrackParticleLinks(const TrackParticleLinks_t &trackParticles)
Set all track particle links at once.
void clearTracks()
Remove all tracks from the vertex.
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
const Amg::Vector3D & position() const
Returns the 3-pos.
The namespace of all packages in PhysicsAnalysis/JetTagging.
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".
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".