ATLAS Offline Software
ModAntikTJetMaker.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "./ModAntikTJetMaker.h"
6 
7 #include <sstream>
8 
9 std::vector<Gep::Jet>
10 Gep::ModAntikTJetMaker::makeJets(const std::vector<Gep::Cluster> &clusters) const {
11 
12  std::vector<Gep::Cluster> constituents = clusters;
13 
14  std::vector<Gep::Jet> v_jets;
15 
16  const unsigned int n_constituents = constituents.size();
17  std::vector< std::vector<int> > v_constitutents_in_jet_indices(n_constituents, std::vector<int>() );
18  // initialize vector of constituents with it's own index
19  for(unsigned int i = 0; i < n_constituents; i++){ v_constitutents_in_jet_indices.at(i).push_back(i); }
20 
21  int niter = 0;
22 
23  //Iterate over clusters
24  while(!constituents.empty() && niter < m_nIter){
25 
26  const unsigned int n_clusters = constituents.size();
27 
28  //create factorized separation list
29  std::vector< std::vector< float > > DeltaR2(n_clusters, std::vector< float >(n_clusters, 0.0));
30  std::vector< float > InvPt2 (n_clusters, 0.0);
31  for (unsigned int i = 0; i < n_clusters; i++){
32  InvPt2[i] = 1/constituents.at(i).vec.Perp2();
33  DeltaR2[i][i] = 1.0;
34  for(unsigned int j = i+1; j < n_clusters; j++){
35  float deltaEta = constituents.at(i).vec.Eta() - constituents.at(j).vec.Eta();
36  float deltaPhi = constituents.at(i).vec.DeltaPhi(constituents.at(j).vec);
37  DeltaR2[i][j] = (deltaEta*deltaEta + deltaPhi*deltaPhi)/(m_jetR*m_jetR);
38  DeltaR2[j][i] = (deltaEta*deltaEta + deltaPhi*deltaPhi)/(m_jetR*m_jetR);
39  }
40  }
41 
42 
43  // indices of minimum DeltaR in i-th row (aka j in d_ij)
44  std::vector< int > minDeltaR2_indices(n_clusters, 0.0);
45  for (unsigned int i = 0; i < n_clusters; i++ ) {
46  minDeltaR2_indices[i] = std::distance( DeltaR2[i].begin(), std::min_element(std::begin(DeltaR2[i]), std::end(DeltaR2[i])) );
47  }
48 
49  //d_ij vector of with minDeltaR2_indices_ij
50  std::vector< float > InvPt2DeltaR2(n_clusters, 0.0);
51  for (unsigned int i = 0; i < n_clusters; i++ ) InvPt2DeltaR2[i] = InvPt2[i]*DeltaR2[i][minDeltaR2_indices[i]];
52 
53  // index of minimum d_ij (aka i in d_ij)
54  int minInvPt2DeltaR2_index = std::distance(InvPt2DeltaR2.begin() , std::min_element(std::begin(InvPt2DeltaR2), std::end(InvPt2DeltaR2)) );
55 
56  // if d_ij < diB, merge j into i, otherwise i is jet
57  if (InvPt2DeltaR2[minInvPt2DeltaR2_index] < InvPt2[minInvPt2DeltaR2_index]){
58  //This is the WTA pt merging scheme
59  // only momentum components are modified
60  TVector3 momentum_vector(constituents.at(minInvPt2DeltaR2_index).vec.Px() + constituents.at(minDeltaR2_indices[minInvPt2DeltaR2_index]).vec.Px(),
61  constituents.at(minInvPt2DeltaR2_index).vec.Py() + constituents.at(minDeltaR2_indices[minInvPt2DeltaR2_index]).vec.Py(),
62  constituents.at(minInvPt2DeltaR2_index).vec.Pz() + constituents.at(minDeltaR2_indices[minInvPt2DeltaR2_index]).vec.Pz());
63 
64  //px, py and pz are recalculated from pt, eta and phi, leaving eta and phi unchanged
65  constituents.at(minInvPt2DeltaR2_index).vec.SetPtEtaPhiE(momentum_vector.Pt(),
66  constituents.at(minInvPt2DeltaR2_index).vec.Eta(),
67  constituents.at(minInvPt2DeltaR2_index).vec.Phi(),
68  momentum_vector.Mag() );
69 
70  // add indices in j to lilst of constituents of subjet i
71  v_constitutents_in_jet_indices.at(minInvPt2DeltaR2_index).insert( v_constitutents_in_jet_indices.at(minInvPt2DeltaR2_index).end(),
72  v_constitutents_in_jet_indices.at(minDeltaR2_indices[minInvPt2DeltaR2_index]).begin(),
73  v_constitutents_in_jet_indices.at(minDeltaR2_indices[minInvPt2DeltaR2_index]).end() );
74 
75  constituents.erase(constituents.begin() + minDeltaR2_indices[minInvPt2DeltaR2_index]);
76  v_constitutents_in_jet_indices.erase(v_constitutents_in_jet_indices.begin() + minDeltaR2_indices[minInvPt2DeltaR2_index]);
77  } else {
78 
79  //create custom jet based on constituents.at(minInvPt2DeltaR2_index)
80  Gep::Jet jet;
81  jet.vec.SetXYZT(constituents.at(minInvPt2DeltaR2_index).vec.Px(), constituents.at(minInvPt2DeltaR2_index).vec.Py(),
82  constituents.at(minInvPt2DeltaR2_index).vec.Pz(), constituents.at(minInvPt2DeltaR2_index).vec.E());
83  jet.constituentsIndices.insert( jet.constituentsIndices.end(),
84  v_constitutents_in_jet_indices.at( minInvPt2DeltaR2_index).begin(),
85  v_constitutents_in_jet_indices.at( minInvPt2DeltaR2_index).end());
86 
87  v_jets.push_back(jet);
88 
89  constituents.erase(constituents.begin() + minInvPt2DeltaR2_index);
90  v_constitutents_in_jet_indices.erase(v_constitutents_in_jet_indices.begin() + minDeltaR2_indices[minInvPt2DeltaR2_index]);
91 
92  }
93 
94  niter++;
95  }
96 
97  return v_jets;
98 }
99 
100 
101 std::string Gep::ModAntikTJetMaker::toString() const {
102 
103  std::stringstream ss;
104  ss << "ModAntikTJetMaker. iterations: " << m_nIter
105  << " rad: " << m_jetR;
106  return ss.str();
107 }
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
Gep::ModAntikTJetMaker::m_jetR
float m_jetR
Definition: ModAntikTJetMaker.h:39
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:66
lumiFormat.i
int i
Definition: lumiFormat.py:85
Gep::ModAntikTJetMaker::makeJets
virtual std::vector< Gep::Jet > makeJets(const std::vector< Gep::Cluster > &clusters) const override
Definition: ModAntikTJetMaker.cxx:10
Gep::Jet
Definition: Trigger/TrigT1/TrigGepPerf/src/Jet.h:12
ModAntikTJetMaker.h
Gep::ModAntikTJetMaker::m_nIter
int m_nIter
Definition: ModAntikTJetMaker.h:38
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
Gep::ModAntikTJetMaker::toString
virtual std::string toString() const override
Definition: ModAntikTJetMaker.cxx:101
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54