ATLAS Offline Software
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 
11 namespace Analysis {
12  // *********************************************************************************
13 
14  // ---------------------------------------------------------------------------------
15  // getPt: returns the pT of a track pair
16  // ---------------------------------------------------------------------------------
18 
19  TLorentzVector momentum(trk1->p4() + trk2->p4() );
20  return momentum.Perp();
21 
22  }
23 
24 
25 
27  const xAOD::TrackParticle* trk2,
28  const xAOD::TrackParticle* trk3)
29  {
30  TLorentzVector momentum( trk1->p4() );
31  momentum+= trk2->p4();
32  momentum+= trk3->p4();
33  return momentum.Perp();
34  }
35 
36 
37  // ---------------------------------------------------------------------------------
38  // getPt: returns the pT of a track quadruplet
39  // ---------------------------------------------------------------------------------
41  const xAOD::TrackParticle* trk2,
42  const xAOD::TrackParticle* trk3,
43  const xAOD::TrackParticle* trk4)
44  {
45  TLorentzVector momentum( trk1->p4() );
46  momentum += trk2->p4();
47  momentum += trk3->p4();
48  momentum += trk4->p4();
49  return momentum.Perp();
50  }
51 
52 
53  // -------------------------------------------------------------------------------------------------
54  // isContainedIn: boolean function which checks if a track (1st argument) is also contained in a
55  // vector (second argument)
56  // -------------------------------------------------------------------------------------------------
57 
58  bool JpsiUpsilonCommon::isContainedIn(const xAOD::TrackParticle* theTrack, const std::vector<const xAOD::TrackParticle*> &theColl) {
59  return std::find(theColl.cbegin(), theColl.cend(), theTrack) != theColl.cend();
60  }
61 
63  bool isContained(false);
65  for (muItr=theColl->begin(); muItr!=theColl->end(); ++muItr) {
66  auto& link = ( *muItr )->inDetTrackParticleLink();
67  if ( link.isValid() && ( *link == theTrack ) ) {isContained=true; break;}
68  }
69  return isContained;
70  }
71 
72  bool JpsiUpsilonCommon::cutRange(double value, double min, double max){
73  return (min<=0.0 || value >= min) && (max <= 0.0 || value <= max);
74  }
75 
76  bool JpsiUpsilonCommon::cutRangeOR(const std::vector<double> &values, double min, double max){
77  for(double m : values) {
78  if( (min<=0.0 || m >= min) && (max <= 0.0 || m <= max)) return true;
79  }
80  return false;
81  }
82 
84  return (min <=0.0 || value >= min);
85  }
86 
87  bool JpsiUpsilonCommon::cutAcceptGreaterOR(const std::vector<double> &values, double min){
88  for(double m : values) {
89  if(min <=0.0 || m >= min) return true;
90  }
91  return false;
92  }
93 
95  const xAOD::VertexContainer* importedPVerticesCollection,
96  const Analysis::PrimaryVertexRefitter *pvRefitter){
97  const xAOD::Vertex* vtx_closest = nullptr; // vertex closest to bVertex track
98  if(importedPVerticesCollection->empty()) return Analysis::CleanUpVertex(nullptr, false);
99  double dc = 1e10;
100  std::vector<const xAOD::Vertex*> tocleanup;
101  if(pvRefitter) tocleanup.reserve(importedPVerticesCollection->size());
102  bool vertexrefitted = false;
103  for (const xAOD::Vertex* PV : *importedPVerticesCollection) {
104  const xAOD::Vertex* refPV = pvRefitter ? pvRefitter->refitVertex(PV, bHelper.vtx(), false) : nullptr;
105  const xAOD::Vertex* vtx = refPV ? refPV : PV;
106  if(refPV) tocleanup.push_back(refPV);
107  TVector3 posPV(vtx->position().x(),vtx->position().y(),vtx->position().z());
108  auto &helperpos = bHelper.vtx()->position();
109  TVector3 posV(helperpos.x(), helperpos.y(), helperpos.z());
110  TVector3 nV = bHelper.totalP().Unit();
111  TVector3 dposV = posPV-posV;
112  double dposVnV = dposV*nV;
113  double d = std::sqrt(std::abs(dposV.Mag2()-dposVnV*dposVnV));
114  if (d<dc) {
115  dc = d;
116  vtx_closest = vtx;
117  vertexrefitted = (vtx_closest == refPV);
118  }
119  }
120  for(auto ptr : tocleanup){
121  if(ptr != vtx_closest) delete ptr;
122  }
123  return Analysis::CleanUpVertex(vtx_closest, vertexrefitted);
124  }
125 
126  void JpsiUpsilonCommon::RelinkVertexTracks(const std::vector<const xAOD::TrackParticleContainer*> &trkcols, xAOD::Vertex* vtx) {
127  std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
128  auto size = vtx->trackParticleLinks().size();
129  for(size_t i = 0; i<size; i++){
130  const xAOD::TrackParticle* mylink= *(vtx->trackParticleLinks()[i]);
131  for(const xAOD::TrackParticleContainer* trkcol : trkcols){
132  auto itr = std::find(trkcol->begin(), trkcol->end(), mylink);
133  if(itr != trkcol->end()){
134  auto mylink=vtx->trackParticleLinks()[i];
135  mylink.setStorableObject(*trkcol, true);
136  newLinkVector.push_back( mylink );
137  break;
138  }
139  }
140  }
141  if(size != newLinkVector.size()){
142  throw std::runtime_error("JpsiUpsilonCommon::RelinkVertexTracks: Could not relink all tracks");
143  }
144  vtx->clearTracks();
145  vtx->setTrackParticleLinks( newLinkVector );
146  }
147 
148  void JpsiUpsilonCommon::RelinkVertexMuons(const std::vector<const xAOD::MuonContainer*>& muoncols, xAOD::Vertex* vtx){
150  using MuonLinkVector = std::vector<MuonLink>;
151  static const SG::AuxElement::Decorator<MuonLinkVector> muonLinksDecor("MuonLinks");
152  const MuonLinkVector &mlinksold = muonLinksDecor(*vtx);
153  auto size = mlinksold.size();
154  MuonLinkVector newmulinks;
155  for(size_t i = 0; i<size; i++){
156  const xAOD::Muon* mylink= *(mlinksold[i]);
157  for(const xAOD::MuonContainer* mucol : muoncols){
158  auto itr = std::find(mucol->begin(), mucol->end(), mylink);
159  if(itr != mucol->end()){
160  auto mylink=mlinksold[i];
161  mylink.setStorableObject(*mucol, true);
162  newmulinks.push_back( mylink );
163  break;
164  }
165  }
166  }
167  if(size != newmulinks.size()){
168  throw std::runtime_error("JpsiUpsilonCommon::RelinkVertexMuons: Could not relink all tracks");
169  }
170  muonLinksDecor(*vtx) = std::move(newmulinks);
171  }
172 }
173 
Analysis::JpsiUpsilonCommon::ClosestRefPV
static Analysis::CleanUpVertex ClosestRefPV(xAOD::BPhysHelper &, const xAOD::VertexContainer *, const Analysis::PrimaryVertexRefitter *)
Definition: JpsiUpsilonCommon.cxx:94
Analysis::CleanUpVertex
Definition: JpsiUpsilonCommon.h:22
xAOD::BPhysHelper::totalP
TVector3 totalP()
: Returns total 3-momentum calculated from the refitted tracks
Definition: BPhysHelper.cxx:374
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::BPhysHelper
Definition: BPhysHelper.h:71
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Analysis::JpsiUpsilonCommon::RelinkVertexMuons
static void RelinkVertexMuons(const std::vector< const xAOD::MuonContainer * > &muoncols, xAOD::Vertex *vtx)
Definition: JpsiUpsilonCommon.cxx:148
hist_file_dump.d
d
Definition: hist_file_dump.py:137
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::Vertex_v1::trackParticleLinks
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
Analysis::JpsiUpsilonCommon::cutAcceptGreaterOR
static bool cutAcceptGreaterOR(const std::vector< double > &values, double min)
Definition: JpsiUpsilonCommon.cxx:87
athena.value
value
Definition: athena.py:124
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
Analysis::JpsiUpsilonCommon::isContainedIn
static bool isContainedIn(const xAOD::TrackParticle *, const std::vector< const xAOD::TrackParticle * > &)
Definition: JpsiUpsilonCommon.cxx:58
PrimaryVertexRefitter.h
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
Analysis::JpsiUpsilonCommon::cutRange
static bool cutRange(double value, double min, double max)
Definition: JpsiUpsilonCommon.cxx:72
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
Analysis::PrimaryVertexRefitter::refitVertex
xAOD::Vertex * refitVertex(const xAOD::Vertex *vertex, const xAOD::Vertex *excludeVertex, bool ReturnCopy=true, int *exitcode=nullptr) const
Definition: PrimaryVertexRefitter.cxx:40
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::TrackParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition: TrackParticle_v1.cxx:129
Analysis::JpsiUpsilonCommon::cutAcceptGreater
static bool cutAcceptGreater(double value, double min)
Definition: JpsiUpsilonCommon.cxx:83
Analysis::PrimaryVertexRefitter
Definition: PrimaryVertexRefitter.h:26
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::Vertex_v1::setTrackParticleLinks
void setTrackParticleLinks(const TrackParticleLinks_t &trackParticles)
Set all track particle links at once.
JpsiUpsilonCommon.h
xAOD::Vertex_v1::clearTracks
void clearTracks()
Remove all tracks from the vertex.
Definition: Vertex_v1.cxx:331
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Analysis::JpsiUpsilonCommon::RelinkVertexTracks
static void RelinkVertexTracks(const std::vector< const xAOD::TrackParticleContainer * > &trkcols, xAOD::Vertex *vtx)
Definition: JpsiUpsilonCommon.cxx:126
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
xAOD::BPhysHelper::vtx
const xAOD::Vertex * vtx() const
Getter method for the cached xAOD::Vertex.
Definition: BPhysHelper.h:108
BPhysHelper.h
: B-physics xAOD helpers.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
MuonLinkVector
std::vector< MuonLink > MuonLinkVector
Definition: BPhysHelper.cxx:22
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Analysis::JpsiUpsilonCommon::getPt
static double getPt(const xAOD::TrackParticle *, const xAOD::TrackParticle *)
Definition: JpsiUpsilonCommon.cxx:17
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Analysis::JpsiUpsilonCommon::cutRangeOR
static bool cutRangeOR(const std::vector< double > &values, double min, double max)
Definition: JpsiUpsilonCommon.cxx:76