33 m_MSVvarFactory(
"Analysis::MSVVariablesFactory",this)
61 return StatusCode::SUCCESS;
68 if (!h_JetCollectionName.
isValid()) {
70 return StatusCode::FAILURE;
79 ATH_MSG_DEBUG(
"#BTAG# Record the BTagging JF Vertex output container");
81 ATH_CHECK( h_BTagJFVtxCollectionName.
record(std::make_unique<xAOD::BTagVertexContainer>(),
82 std::make_unique<xAOD::BTagVertexAuxContainer>()) );
87 ATH_MSG_DEBUG(
"#BTAG# Record the BTagging Secondary Vertex output container");
89 ATH_CHECK( h_BTagSVCollectionName.
record(std::make_unique<xAOD::VertexContainer>(),
90 std::make_unique<xAOD::VertexAuxContainer>()) );
93 if (h_JetCollectionName->
empty()) {
95 return StatusCode::SUCCESS;
99 if (!h_TrackCollectionName.
isValid()) {
101 return StatusCode::FAILURE;
110 if (!h_VertexCollectionName.
isValid()) {
112 return StatusCode::FAILURE;
117 if (!h_VxSecVertexInfoName.
isValid()) {
119 return StatusCode::FAILURE;
123 if (h_VxSecVertexInfoName->
size() != h_JetCollectionName->
size()) {
124 ATH_MSG_ERROR(
"Size of jet container different than size of VxSecVertexInfo");
125 return StatusCode::FAILURE;
128 unsigned int nVertexes = h_VertexCollectionName->
size();
129 if (nVertexes == 0) {
131 return StatusCode::FAILURE;
133 for (
const auto *fz : *h_VertexCollectionName) {
140 if (! primaryVertex) {
141 ATH_MSG_DEBUG(
"#BTAG# No vertex labeled as VxType::PriVtx!");
154 for (
const xAOD::Jet* jetToTag : *h_JetCollectionName) {
156 if(myVertexInfo !=
nullptr) {
161 ATH_MSG_ERROR(
"#BTAG# error filling variables in MSVVariablesFactory" );
166 ATH_MSG_DEBUG(
"#BTAG# dynamic_cast failed for a non-nullptr myVertexInfo!");
174 for (
const xAOD::Jet* jetToTag : *h_JetCollectionName) {
176 std::vector< ElementLink< xAOD::VertexContainer > > SVertexLinks;
177 if(myVertexInfo !=
nullptr) {
187 ATH_MSG_DEBUG(
"#BTAG# dynamic_cast failed for a non-nullptr myVertexInfo!");
190 h_jetSVLinkName(*jetToTag) = SVertexLinks;
196 for (
const xAOD::Jet* jetToTag : *h_JetCollectionName) {
198 std::vector< ElementLink< xAOD::BTagVertexContainer > > JFVtxLinks;
199 if(myVertexInfo !=
nullptr) {
201 ATH_MSG_DEBUG(
"#BTAG# Found VxJetFitterVertexInfo information");
209 ATH_MSG_DEBUG(
"#BTAG# dynamic_cast failed for a non-nullptr myVertexInfo!");
212 h_jetSVLinkName(*jetToTag) = JFVtxLinks;
220 return StatusCode::SUCCESS;
226 std::vector<xAOD::Vertex*>::const_iterator verticesBegin = myVertexInfoVKal->
vertices().begin();
227 std::vector<xAOD::Vertex*>::const_iterator verticesEnd = myVertexInfoVKal->
vertices().end();
229 for (std::vector<xAOD::Vertex*>::const_iterator verticesIter=verticesBegin; verticesIter!=verticesEnd;++verticesIter) {
235 SVertexLinks->push_back(linkBTagVertex);
239 return StatusCode::SUCCESS;
249 const std::vector<Trk::VxJetCandidate*>& JFvertices = myVertexInfoJetFitter->
verticesJF();
252 if (!JFvertices.empty()) {
256 return StatusCode::SUCCESS;
261 typedef std::map<Trk::VxVertexOnJetAxis*, std::vector<std::pair<Trk::VxVertexOnJetAxis*,float> > > map2vtx;
262 map2vtx inverseCompMap;
264 if (ClusteringTable !=
nullptr) {
266 std::map<float,Trk::PairOfVxVertexOnJetAxis>::const_iterator mapiter = mapPairVtxOnJetAxis.begin();
267 for(;mapiter != mapPairVtxOnJetAxis.end(); ++mapiter){
271 float comp = mapiter->first;
273 std::pair<Trk::VxVertexOnJetAxis*,float>
pair1(vtx1,
comp);
274 std::pair<Trk::VxVertexOnJetAxis*,float>
pair2(vtx1,
comp);
276 inverseCompMap[vtx1].push_back(
pair2);
277 inverseCompMap[vtx2].push_back(
pair1);
284 ATH_MSG_DEBUG(
"#BTAG# VerticesOnJetAxis of VxJetCandidate size: " << Vtxonjetaxes.size());
285 std::vector<Trk::VxVertexOnJetAxis*>::const_iterator iterBegin = Vtxonjetaxes.begin();
286 std::vector<Trk::VxVertexOnJetAxis*>::const_iterator iterEnd = Vtxonjetaxes.end();
290 nVtx = Vtxonjetaxes.size();
291 std::map<Trk::VxVertexOnJetAxis*, ElementLink< xAOD::BTagVertexContainer> > oldnewmap;
293 for (std::vector<Trk::VxVertexOnJetAxis*>::const_iterator
it=iterBegin;
it!=iterEnd; ++
it) {
298 comptoPV = (*it)->getCompatibilityToPrimaryVtx();
299 const std::vector<Trk::VxTrackAtVertex*> & trackatVtx = (*it)->getTracksAtVertex();
300 std::vector<Trk::VxTrackAtVertex*>::const_iterator itrBegin = trackatVtx.begin();
301 std::vector<Trk::VxTrackAtVertex*>::const_iterator itrEnd = trackatVtx.end();
302 std::vector< float> tmpchi2;
303 std::vector< float> tmpndf;
304 std::vector< ElementLink< xAOD::TrackParticleContainer > > trkLinks;
305 std::vector< float> tmpRefPx;
306 std::vector< float> tmpRefPy;
307 std::vector< float> tmpRefPz;
310 for (std::vector<Trk::VxTrackAtVertex*>::const_iterator itr=itrBegin; itr!=itrEnd; ++itr) {
315 tmpchi2.push_back(
float(tpchi2));
316 tmpndf.push_back(
float(tpndf));
320 if (!trkLinkTPxAOD) {
321 ATH_MSG_WARNING(
"#BTAG# bad ITrackLink is not a LinkToXAODTrackParticle");
328 trkLinks.push_back(tpel);
333 tmpRefPx.push_back(mytrack.x());
334 tmpRefPy.push_back(mytrack.y());
335 tmpRefPz.push_back(mytrack.z());
340 bTagJFVertexContainer->
push_back(newbtagVtx);
354 JFVerticesLinks->push_back(linkBTagVertex);
355 oldnewmap.insert(std::make_pair(*
it,linkBTagVertex));
358 if(ClusteringTable !=
nullptr){
359 for (std::vector<Trk::VxVertexOnJetAxis*>::const_iterator
it=iterBegin;
it!=iterEnd; ++
it) {
360 std::vector< ElementLink< xAOD::BTagVertexContainer > > JFCompLinks;
361 std::vector<float> JFCompValues;
365 if(itmap == inverseCompMap.end()){
366 ATH_MSG_DEBUG(
"#BTAG# JF compatibility value in map2vtx map not found ");
372 std::vector<std::pair<Trk::VxVertexOnJetAxis*,float> > tmpvectpair = itmap->second;
374 for(
auto & icomppair : tmpvectpair){
375 std::map<Trk::VxVertexOnJetAxis*, ElementLink< xAOD::BTagVertexContainer> >
::iterator JFOlNewIter = oldnewmap.find(icomppair.first);
377 if(JFOlNewIter == oldnewmap.end()){
382 JFCompLinks.push_back(JFOlNewIter->second);
383 JFCompValues.push_back(icomppair.second);
392 ATH_MSG_DEBUG(
"#BTAGJF# size vtxPosition "<<vtxPositions.size());
393 std::vector< float > fittedPosition = std::vector<float>(nVtx+5,-1);
394 std::vector< float > fittedCov = std::vector<float>(nVtx+5,-1);
395 if(vtxPositions.rows()>4 ) {
402 fittedCov[0] = vtxCovMatrix(0,0);
403 fittedCov[1] = vtxCovMatrix(1,1);
404 fittedCov[2] = vtxCovMatrix(2,2);
405 fittedCov[3] = vtxCovMatrix(3,3);
406 fittedCov[4] = vtxCovMatrix(4,4);
410 for(
int i=0;
i<nVtx; ++
i){
411 fittedPosition[
i+5] = vtxPositions[
i+5];
412 fittedCov[
i+5] = vtxCovMatrix(
i+5,
i+5);
417 std::vector<Trk::VxTrackAtVertex*>::const_iterator irBegin = trackatPV.begin();
418 std::vector<Trk::VxTrackAtVertex*>::const_iterator irEnd = trackatPV.end();
419 std::vector< float > tracksAtPVchi2;
420 std::vector< float > tracksAtPVndf;
421 std::vector< ElementLink< xAOD::TrackParticleContainer > > tracksAtPVlinks;
423 for (std::vector<Trk::VxTrackAtVertex*>::const_iterator
it=irBegin;
it!=irEnd; ++
it) {
427 tracksAtPVchi2.push_back(
float(tmpchi2));
428 tracksAtPVndf.push_back(
float(tmpndf));
433 if (!trkLinkTPxAOD) {
434 ATH_MSG_WARNING(
"#BTAG# bad ITrackLink is not a LinkToXAODTrackParticle");
440 tracksAtPVlinks.push_back(tpel);
447 return StatusCode::SUCCESS;