ATLAS Offline Software
VertexPlus1TrackCascade.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 
12 
13 namespace DerivationFramework {
14 
15 
16  typedef std::vector<const xAOD::TrackParticle*> TrackBag;
17 
19 
20  // retrieving vertex Fitter
21  if ( m_iVertexFitter.retrieve().isFailure() ) {
22  ATH_MSG_FATAL("Failed to retrieve tool " << m_iVertexFitter);
23  return StatusCode::FAILURE;
24  } else {
25  ATH_MSG_DEBUG("Retrieved tool " << m_iVertexFitter);
26  }
27 
28  // Get the track selector tool from ToolSvc
29  if ( m_trkSelector.retrieve().isFailure() ) {
30  ATH_MSG_FATAL("Failed to retrieve tool " << m_trkSelector);
31  return StatusCode::FAILURE;
32  } else {
33  ATH_MSG_DEBUG("Retrieved tool " << m_trkSelector);
34  }
35  if(!m_vertexContainerKey.key().empty()) ATH_CHECK(m_vertexContainerKey.initialize());
37  if(!m_MuonsUsedInJpsiKey.key().empty()) ATH_CHECK(m_MuonsUsedInJpsiKey.initialize());
38 
39  return StatusCode::SUCCESS;
40  }
41 
43 
44  return StatusCode::SUCCESS;
45 
46  }
47 
48  VertexPlus1TrackCascade::VertexPlus1TrackCascade(const std::string& t, const std::string& n, const IInterface* p) : AthAlgTool(t,n,p),
49  m_vertexContainerKey(""),
50  m_TrackPContainerKey(""),
51  m_MuonsUsedInJpsiKey(""),
52  m_Vtx1MassConstraint(0.),
53  m_Vtx2MassConstraint(0.0),
54  m_trkThresholdPt(0.0),
55  m_trkMaxEta(102.5),
56 // m_BThresholdPt(0.0),
57 // m_BMassUpper(0.0),
58 // m_BMassLower(0.0),
59  m_roughMassLower(0.0),
60  m_roughMassUpper(0.0),
61  m_iVertexFitter("Trk::TrkVKalVrtFitter"),
62  m_trkSelector("InDet::TrackSelectorTool")
63  {
64  declareProperty("InitialVertices", m_vertexContainerKey);
65  declareProperty("TrackParticleCollection", m_TrackPContainerKey);
66  declareProperty("MuonCollection", m_MuonsUsedInJpsiKey);
67  declareProperty("MassHypthesis", m_massHypothesis);
68  declareProperty("MassContraintTracksVtx1", m_massConstraintTracksVtx1);
69  declareProperty("MassContraintTracksVtx2", m_massConstraintTracksVtx2);
70 
71  declareProperty("Vtx1MassConstraint", m_Vtx1MassConstraint);
72  declareProperty("Vtx2MassConstraint", m_Vtx2MassConstraint);
73 
74  declareProperty("trkThresholdPtCut", m_trkThresholdPt);
75  declareProperty("trkMassEtaCut", m_trkMaxEta);
76 // declareProperty("BThresholdPtCut", m_BThresholdPt);
77 // declareProperty("BMassUpperCut", m_BMassUpper);
78 // declareProperty("BMassLowerCut", m_BMassLower);
79 
80  declareProperty("RoughMassUpperCut", m_roughMassLower);
81  declareProperty("RoughMassLowerCut", m_roughMassUpper);
82 
83  }
84 
86 
87  double VertexPlus1TrackCascade::getInvariantMass(const TrackBag &Tracks, const std::vector<double> &massHypotheses){
88 
89  TLorentzVector total;
90  total.SetVectM(Tracks[0]->p4().Vect(), massHypotheses[0]);
91  TLorentzVector temp;
92  for(size_t i=1; i < Tracks.size(); i++){
93  temp.SetVectM(Tracks[i]->p4().Vect(), massHypotheses[i]);
94  total += temp;
95  }
96  return total.M();
97  }
98 
100  bool isContained(false);
101  for (auto muItr=theColl->cbegin(); muItr!=theColl->cend(); ++muItr) {
102  auto& link = ( *muItr )->inDetTrackParticleLink();
103  if ( link.isValid() && ( *link == theTrack ) ) {isContained=true; break;}
104  }
105  return isContained;
106  }
107 
108  StatusCode VertexPlus1TrackCascade::performSearch(std::vector<Trk::VxCascadeInfo*> *cascadeinfoContainer) const
109  {
110  ATH_MSG_DEBUG( "VertexPlus1TrackCascade::performSearch" );
111  assert(cascadeinfoContainer!=nullptr);
113  if(!vertexContainer.isValid()){
114  ATH_MSG_ERROR("No VertexContainer with key " << m_vertexContainerKey.key() << " found in StoreGate. BCandidates will be EMPTY!");
115  return StatusCode::FAILURE;
116  }
117 
118  // Get tracks
120  if(!TrackPContainer.isValid()){
121  ATH_MSG_ERROR("No track particle collection with name " << m_TrackPContainerKey.key() << " found in StoreGate!");
122  return StatusCode::FAILURE;
123  }
124 
125 
126  // Get the muon collection used to build the J/psis
127  const xAOD::MuonContainer* importedMuonCollection = nullptr;
128  if (!m_MuonsUsedInJpsiKey.key().empty()) {
130  if(handle.isValid()) importedMuonCollection = handle.cptr();
131  else {
132  ATH_MSG_FATAL("problem retrieving MuonContainer " << m_MuonsUsedInJpsiKey.key());
133  return StatusCode::FAILURE;
134  }
135  ATH_MSG_DEBUG("Muon container size "<< importedMuonCollection->size());
136  }
137 
138  // Select the inner detector tracks
139  TrackBag theIDTracksAfterSelection;
140  for (auto tp : *TrackPContainer){
141  if ( tp->pt()<m_trkThresholdPt ) continue;
142  if ( fabs(tp->eta())>m_trkMaxEta ) continue;
143  if (importedMuonCollection!=NULL) {
144  if (isContainedIn(tp, importedMuonCollection)) continue;
145  }
146  if ( m_trkSelector->decision(*tp, NULL) ) theIDTracksAfterSelection.push_back(tp);
147  }
148 
149  const std::vector<double> &fullMassHypoth = (m_massHypothesis);
150  const std::vector<double> initialVertexMassHypo(fullMassHypoth.begin(), fullMassHypoth.end()-1);
151 
152  TrackBag originalVertexTracks(initialVertexMassHypo.size());
153  TrackBag secondVertexTracks(fullMassHypoth.size());
154 
155  const std::vector< Trk::VertexID > emptyVtxList;
156  TrackBag ConstraintTracksVtx1(m_massConstraintTracksVtx1.size());
157  TrackBag ConstraintTracksVtx2(m_massConstraintTracksVtx2.size());
158 
159  assert(fullMassHypoth.size() == secondVertexTracks.size());
160 
161  for(auto vertex : *vertexContainer){ //Iterate over previous vertices
162 
163  size_t OriginaltrackNum = vertex->nTrackParticles();
164  if(initialVertexMassHypo.size() != OriginaltrackNum){
165  ATH_MSG_FATAL("Mass hypothesis not correctly set");
166  return StatusCode::FAILURE;
167  }
168  for(size_t i = 0;i<OriginaltrackNum;i++)
169  originalVertexTracks[i] = secondVertexTracks[i] = (vertex->trackParticle(i));
170 
171  for(auto newtrack : theIDTracksAfterSelection){
172  //Skip any track already used in vertex
173  if(std::find(originalVertexTracks.begin(), originalVertexTracks.end(), newtrack) != originalVertexTracks.end()) continue;
174 
175  secondVertexTracks.back() = newtrack;
176 
177  double roughmass = getInvariantMass(secondVertexTracks, fullMassHypoth);
178 
179  if(m_roughMassUpper > 0.0 && (roughmass < m_roughMassLower || roughmass > m_roughMassUpper)) continue;
180 
181  std::unique_ptr<Trk::IVKalState> state = m_iVertexFitter->makeState();
182  m_iVertexFitter->setRobustness( 0, *state );
183 
184  auto vID1 = m_iVertexFitter->startVertex( originalVertexTracks, initialVertexMassHypo, *state );
185  auto vID2 = m_iVertexFitter->nextVertex( secondVertexTracks, fullMassHypoth, *state );
186 
187  if(!m_massConstraintTracksVtx1.empty()){
188  for(size_t i =0; i<m_massConstraintTracksVtx1.size(); i++) ConstraintTracksVtx1[i] = originalVertexTracks.at(m_massConstraintTracksVtx1[i]);
189  if( !m_iVertexFitter->addMassConstraint( vID1, ConstraintTracksVtx1, emptyVtxList, *state, m_Vtx1MassConstraint ).isSuccess() ) {
190  ATH_MSG_WARNING( "cascade fit: addMassConstraint failed" );
191  }
192  }
193 
194  if(!m_massConstraintTracksVtx2.empty()){
195  for(size_t i =0; i<m_massConstraintTracksVtx2.size(); i++) ConstraintTracksVtx2[i] = secondVertexTracks.at(m_massConstraintTracksVtx2[i]);
196  if( !m_iVertexFitter->addMassConstraint( vID2, ConstraintTracksVtx2, emptyVtxList,*state, m_Vtx2MassConstraint ).isSuccess() ) {
197  ATH_MSG_WARNING( "cascade fit: addMassConstraint failed" );
198  }
199  }
200 
201  auto result = m_iVertexFitter->fitCascade(*state);
202  if(result ==nullptr ){ ATH_MSG_WARNING("Cascade Fit failed"); continue; }
203  assert(result->vertices().size()==2);
204  cascadeinfoContainer->push_back(result);
205 
206  }
207 
208  }
209  ATH_MSG_DEBUG("cascadeinfoContainer size " << cascadeinfoContainer->size());
210  return StatusCode::SUCCESS;
211  }
212 
213 
214 }
215 
216 
InDetGNNHardScatterSelection::getter_utils::Tracks
std::vector< const xAOD::TrackParticle * > Tracks
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/CustomGetterUtils.h:49
DerivationFramework::VertexPlus1TrackCascade::m_massConstraintTracksVtx2
std::vector< int > m_massConstraintTracksVtx2
Definition: VertexPlus1TrackCascade.h:44
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
DerivationFramework::VertexPlus1TrackCascade::finalize
StatusCode finalize() override
Definition: VertexPlus1TrackCascade.cxx:42
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::VertexPlus1TrackCascade::performSearch
StatusCode performSearch(std::vector< Trk::VxCascadeInfo * > *cascadeinfoContainer) const
Definition: VertexPlus1TrackCascade.cxx:108
DerivationFramework::VertexPlus1TrackCascade::m_roughMassLower
double m_roughMassLower
Definition: VertexPlus1TrackCascade.h:54
DerivationFramework::VertexPlus1TrackCascade::m_trkThresholdPt
double m_trkThresholdPt
Definition: VertexPlus1TrackCascade.h:48
ParticleTest.tp
tp
Definition: ParticleTest.py:25
DerivationFramework::VertexPlus1TrackCascade::m_Vtx2MassConstraint
double m_Vtx2MassConstraint
Definition: VertexPlus1TrackCascade.h:46
DataVector::cend
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
DerivationFramework::VertexPlus1TrackCascade::getInvariantMass
static double getInvariantMass(const std::vector< const xAOD::TrackParticle * > &Tracks, const std::vector< double > &massHypotheses)
Definition: VertexPlus1TrackCascade.cxx:87
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::VertexPlus1TrackCascade::m_roughMassUpper
double m_roughMassUpper
Definition: VertexPlus1TrackCascade.h:55
DerivationFramework::VertexPlus1TrackCascade::m_TrackPContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackPContainerKey
Definition: VertexPlus1TrackCascade.h:38
DerivationFramework::VertexPlus1TrackCascade::m_trkSelector
ToolHandle< Trk::ITrackSelectorTool > m_trkSelector
Definition: VertexPlus1TrackCascade.h:57
TrkVKalVrtFitter.h
VertexPlus1TrackCascade.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
DerivationFramework::VertexPlus1TrackCascade::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition: VertexPlus1TrackCascade.h:37
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::TrackBag
std::vector< const xAOD::TrackParticle * > TrackBag
Definition: BPhysAddMuonBasedInvMass.h:32
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework::VertexPlus1TrackCascade::VertexPlus1TrackCascade
VertexPlus1TrackCascade(const std::string &t, const std::string &n, const IInterface *p)
Definition: VertexPlus1TrackCascade.cxx:48
DerivationFramework::VertexPlus1TrackCascade::m_Vtx1MassConstraint
double m_Vtx1MassConstraint
Definition: VertexPlus1TrackCascade.h:45
DerivationFramework::VertexPlus1TrackCascade::~VertexPlus1TrackCascade
~VertexPlus1TrackCascade()
Definition: VertexPlus1TrackCascade.cxx:85
IVertexFitter.h
VxCascadeInfo.h
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
DerivationFramework::VertexPlus1TrackCascade::isContainedIn
static bool isContainedIn(const xAOD::TrackParticle *theTrack, const xAOD::MuonContainer *theColl)
Definition: VertexPlus1TrackCascade.cxx:99
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DataVector::cbegin
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
DerivationFramework::VertexPlus1TrackCascade::m_iVertexFitter
ToolHandle< Trk::TrkVKalVrtFitter > m_iVertexFitter
Definition: VertexPlus1TrackCascade.h:56
AthAlgTool
Definition: AthAlgTool.h:26
ITrackSelectorTool.h
DerivationFramework::VertexPlus1TrackCascade::m_trkMaxEta
double m_trkMaxEta
Definition: VertexPlus1TrackCascade.h:49
DerivationFramework::VertexPlus1TrackCascade::m_MuonsUsedInJpsiKey
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonsUsedInJpsiKey
Definition: VertexPlus1TrackCascade.h:39
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DerivationFramework::VertexPlus1TrackCascade::m_massConstraintTracksVtx1
std::vector< int > m_massConstraintTracksVtx1
Definition: VertexPlus1TrackCascade.h:43
DerivationFramework::VertexPlus1TrackCascade::initialize
StatusCode initialize() override
Definition: VertexPlus1TrackCascade.cxx:18
DerivationFramework::VertexPlus1TrackCascade::m_massHypothesis
std::vector< double > m_massHypothesis
Definition: VertexPlus1TrackCascade.h:41