ATLAS Offline Software
SecVertexTruthMatchAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include "TMath.h"
10 #include "TH1.h"
11 #include "TEfficiency.h"
12 
13 const float GeV = 1000.;
14 
15 namespace CP {
16 
17  SecVertexTruthMatchAlg::SecVertexTruthMatchAlg( const std::string& name, ISvcLocator* svcLoc )
18  : EL::AnaAlgorithm( name, svcLoc ) {}
19 
21 
22  // Initializing Keys
23  ATH_CHECK(m_secVtxContainerKey.initialize());
24  ATH_CHECK(m_truthVtxContainerKey.initialize());
26 
27  // Retrieving the tool
28  ATH_CHECK(m_matchTool.retrieve());
29 
30  if(m_writeHistograms) {
31  std::vector<std::string> recoTypes{"All", "Matched", "Merged", "Fake", "Split", "Other"};
32  std::vector<std::string> truthTypes{"Inclusive", "Reconstructable", "Accepted", "Seeded", "Reconstructed", "ReconstructedSplit"};
33 
34  ANA_CHECK (book(TH1F("RecoVertex/matchType", "Vertex Match Type", 65, -0.5, 64.5)));
35 
36  for(const auto& recoType : recoTypes) {
37  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_x").c_str(), "Reco vertex x [mm]", 1000, -500, 500)));
38  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_y").c_str(), "Reco vertex y [mm]", 1000, -500, 500)));
39  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_z").c_str(), "Reco vertex z [mm]", 1000, -500, 500)));
40  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Lxy").c_str(), "Reco vertex L_{xy} [mm]", 500, 0, 500)));
41  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_pT").c_str(), "Reco vertex p_{T} [GeV]", 100, 0, 100)));
42  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_eta").c_str(), "Reco vertex #eta", 100, -5, 5)));
43  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_phi").c_str(), "Reco vertex #phi", 100, -TMath::Pi(), TMath::Pi())));
44  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_mass").c_str(), "Reco vertex mass [GeV]", 500, 0, 100)));
45  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_mu").c_str(), "Reco vertex Red. Mass [GeV]", 500, 0, 100)));
46  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_chi2").c_str(), "Reco vertex recoChi2", 100, 0, 10)));
47  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_dir").c_str(), "Reco vertex recoDirection", 100, -1, 1)));
48  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_charge").c_str(), "Reco vertex recoCharge", 20, -10, 10)));
49  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_H").c_str(), "Reco vertex H [GeV]", 100, 0, 100)));
50  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_HT").c_str(), "Reco vertex Mass [GeV]", 100, 0, 100)));
51  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_minOpAng").c_str(), "Reco vertex minOpAng", 100, -1, 1)));
52  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_maxOpAng").c_str(), "Reco vertex maxOpAng", 100, -1, 1)));
53  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_maxdR").c_str(), "Reco vertex maxDR", 100, 0, 10)));
54  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_mind0").c_str(), "Reco vertex min d0 [mm]", 100, 0, 100)));
55  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_maxd0").c_str(), "Reco vertex max d0 [mm]", 100, 0, 100)));
56  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_ntrk").c_str(), "Reco vertex n tracks", 30, 0, 30)));
57 
58  // tracks
59  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_qOverP").c_str(), "Reco track qOverP ", 100, 0, .01)));
60  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_theta").c_str(), "Reco track theta ", 64, 0, 3.2)));
61  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_E").c_str(), "Reco track E ", 100, 0, 100)));
62  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_M").c_str(), "Reco track M ", 100, 0, 10)));
63  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Pt").c_str(), "Reco track Pt ", 100, 0, 100)));
64  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Px").c_str(), "Reco track Px ", 100, 0, 100)));
65  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Py").c_str(), "Reco track Py ", 100, 0, 100)));
66  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Pz").c_str(), "Reco track Pz ", 100, 0, 100)));
67  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Eta").c_str(), "Reco track Eta ", 100, -5, 5)));
68  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Phi").c_str(), "Reco track Phi ", 63, -3.2, 3.2)));
69  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_D0").c_str(), "Reco track D0 ", 300, -300, 300)));
70  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Z0").c_str(), "Reco track Z0 ", 500, -500, 500)));
71  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_errD0").c_str(), "Reco track errD0 ", 300, 0, 30)));
72  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_errZ0").c_str(), "Reco track errZ0 ", 500, 0, 50)));
73  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_Chi2").c_str(), "Reco track Chi2 ", 100, 0, 10)));
74  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_nDoF").c_str(), "Reco track nDoF ", 100, 0, 100)));
75  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_Trk_charge").c_str(), "Reco track charge ", 3, -1.5, 1.5)));
76 
77  // truth matching -- don't book for non-matched vertices
78  if ( recoType != "All" and recoType != "Fake" ) {
79  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_positionRes_R").c_str(), "Position resolution for vertices matched to truth decays", 400, -20, 20)));
80  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_positionRes_Z").c_str(), "Position resolution for vertices matched to truth decays", 400, -20, 20)));
81  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_matchScore_weight").c_str(), "Vertex Match Score (weight)", 101, 0, 1.01)));
82  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_matchScore_pt").c_str(), "Vertex Match Score (pT)", 101, 0, 1.01)));
83  ANA_CHECK (book(TH1F(("RecoVertex/" + recoType + "_matchedTruthID").c_str(), "Vertex Truth Match ID", 100, 0, 100)));
84  }
85  }
86  for(const auto& truthType : truthTypes) {
87  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_x").c_str(), "Truth vertex x [mm]", 1000, -500, 500)));
88  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_y").c_str(), "Truth vertex y [mm]", 500, -500, 500)));
89  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_z").c_str(), "Truth vertex z [mm]", 500, -500, 500)));
90  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_R").c_str(), "Truth vertex r [mm]", 6000, 0, 600)));
91  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_distFromPV").c_str(), "Truth vertex distFromPV [mm]", 500, 0, 500)));
92  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Eta").c_str(), "Truth vertex Eta", 100, -5, 5)));
93  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Phi").c_str(), "Truth vertex Phi", 64, -3.2, 3.2)));
94  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Ntrk_out").c_str(), "Truth vertex n outgoing tracks", 100, 0, 100)));
95  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Parent_E").c_str(), "Reco track E", 100, 0, 100)));
96  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Parent_M").c_str(), "Reco track M", 500, 0, 500)));
97  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Parent_Pt").c_str(), "Reco track Pt", 100, 0, 100)));
98  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Parent_Eta").c_str(), "Reco track Eta", 100, -5, 5)));
99  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Parent_Phi").c_str(), "Reco track Phi", 63, -3.2, 3.2)));
100  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_Parent_charge").c_str(), "Reco track charge", 3, -1, 1)));
101  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_ParentProdX").c_str(), "truthParentProd vertex x [mm]", 500, -500, 500)));
102  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_ParentProdY").c_str(), "truthParentProd vertex y [mm]", 500, -500, 500)));
103  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_ParentProdZ").c_str(), "truthParentProd vertex z [mm]", 500, -500, 500)));
104  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_ParentProdR").c_str(), "truthParentProd vertex r [mm]", 6000, 0, 600)));
105  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_ParentProddistFromPV").c_str(), "truthParentProd vertex distFromPV [mm]", 500, 0, 500)));
106  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_ParentProdEta").c_str(), "truthParentProd vertex Eta", 100, -5, 5)));
107  ANA_CHECK (book(TH1F(("TruthVertex/" + truthType + "_ParentProdPhi").c_str(), "truthParentProd vertex Phi", 64, -3.2, 3.2)));
108  }
109  // now add the efficiencies
110  Double_t bins[] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 100, 125, 150, 200, 300, 500};
111  size_t nbins = sizeof(bins)/sizeof(bins[0])-1;
112  ANA_CHECK (book(TEfficiency("Acceptance", "Acceptance", nbins, bins)));
113  ANA_CHECK (book(TEfficiency("eff_seed", "Seed efficiency", nbins, bins)));
114  ANA_CHECK (book(TEfficiency("eff_core", "Core efficiency", nbins, bins)));
115  ANA_CHECK (book(TEfficiency("eff_total", "Total efficiency", nbins, bins)));
116  }
117 
118  return StatusCode::SUCCESS;
119  }
120 
122 
123  //Retrieve the vertices:
127 
128  std::vector<const xAOD::Vertex*> recoVerticesToMatch;
129  std::vector<const xAOD::TruthVertex*> truthVerticesToMatch;
130 
131  for(const auto recoVertex : *recoVertexContainer) {
132  xAOD::VxType::VertexType vtxType = static_cast<xAOD::VxType::VertexType>( recoVertex->vertexType() );
133 
134  if(vtxType != xAOD::VxType::SecVtx ){
135  ATH_MSG_DEBUG("Vertex not labeled as secondary");
136  continue;
137  }
138  recoVerticesToMatch.push_back(recoVertex);
139  }
140 
141  for(const auto truthVertex : *truthVertexContainer) {
142  if(truthVertex->nIncomingParticles() != 1) {
143  continue;
144  }
145  const xAOD::TruthParticle* truthPart = truthVertex->incomingParticle(0);
146  if(not truthPart) {
147  continue;
148  }
149  if(std::find(m_targetPDGIDs.begin(), m_targetPDGIDs.end(), std::abs(truthPart->pdgId())) == m_targetPDGIDs.end()) {
150  continue;
151  }
152  if(truthVertex->nOutgoingParticles() < 2) {
153  continue;
154  }
155  truthVerticesToMatch.push_back(truthVertex);
156  }
157 
158  //pass to the tool for decoration:
159  ATH_CHECK( m_matchTool->matchVertices( recoVerticesToMatch, truthVerticesToMatch, trackParticleContainer.cptr() ) );
160 
161  if(m_writeHistograms) {
162  static const xAOD::Vertex::Decorator<int> matchTypeDecor("vertexMatchType");
163  for(const auto& secVtx : recoVerticesToMatch) {
164  int matchTypeBitset = matchTypeDecor(*secVtx);
165  hist("RecoVertex/matchType")->Fill(matchTypeBitset);
166 
167  if(InDetSecVtxTruthMatchUtils::isMatched(matchTypeBitset)) {
168  fillRecoHistograms(secVtx, "Matched");
169  }
170  if(InDetSecVtxTruthMatchUtils::isMerged(matchTypeBitset)) {
171  fillRecoHistograms(secVtx, "Merged");
172  }
173  if(InDetSecVtxTruthMatchUtils::isFake(matchTypeBitset)) {
174  fillRecoHistograms(secVtx, "Fake");
175  }
176  if(InDetSecVtxTruthMatchUtils::isSplit(matchTypeBitset)) {
177  fillRecoHistograms(secVtx, "Split");
178  }
179  if(InDetSecVtxTruthMatchUtils::isOther(matchTypeBitset)) {
180  fillRecoHistograms(secVtx, "Other");
181  }
182  fillRecoHistograms(secVtx, "All");
183  }
184 
185  static const xAOD::Vertex::Decorator<int> truthTypeDecor("truthVertexMatchType");
186  for(const auto& truthVtx : truthVerticesToMatch) {
187  int truthTypeBitset = truthTypeDecor(*truthVtx);
188  if(InDetSecVtxTruthMatchUtils::isReconstructable(truthTypeBitset)) {
189  fillTruthHistograms(truthVtx, "Reconstructable");
190 
191  // fill efficiencies
192  efficiency("Acceptance")->Fill(InDetSecVtxTruthMatchUtils::isAccepted(truthTypeBitset), truthVtx->perp());
193  efficiency("eff_total")->Fill(InDetSecVtxTruthMatchUtils::isReconstructed(truthTypeBitset), truthVtx->perp());
194  }
195  if(InDetSecVtxTruthMatchUtils::isAccepted(truthTypeBitset)) {
196  fillTruthHistograms(truthVtx, "Accepted");
197  efficiency("eff_seed")->Fill(InDetSecVtxTruthMatchUtils::isSeeded(truthTypeBitset), truthVtx->perp());
198  }
199  if(InDetSecVtxTruthMatchUtils::isSeeded(truthTypeBitset)) {
200  fillTruthHistograms(truthVtx, "Seeded");
201  efficiency("eff_core")->Fill(InDetSecVtxTruthMatchUtils::isReconstructed(truthTypeBitset), truthVtx->perp());
202  }
203  if(InDetSecVtxTruthMatchUtils::isReconstructed(truthTypeBitset)) {
204  fillTruthHistograms(truthVtx, "Reconstructed");
205  }
207  fillTruthHistograms(truthVtx, "ReconstructedSplit");
208  }
209  fillTruthHistograms(truthVtx, "Inclusive");
210 
211  }
212  }
213 
214  return StatusCode::SUCCESS;
215 
216  }
217  void SecVertexTruthMatchAlg::fillRecoHistograms(const xAOD::Vertex* secVtx, const std::string& matchType) {
218 
219  // set of accessors for tracks and weights
221  xAOD::Vertex::ConstAccessor<std::vector<float> > weightAcc("trackWeights");
222 
223  // set of decorators for truth matching info
224  const xAOD::Vertex::Decorator<std::vector<InDetSecVtxTruthMatchUtils::VertexTruthMatchInfo> > matchInfoDecor("truthVertexMatchingInfos");
225 
226  TVector3 reco_pos(secVtx->x(), secVtx->y(), secVtx->z());
227  float Lxy = reco_pos.Perp();
228 
229  size_t ntracks;
230  const xAOD::Vertex::TrackParticleLinks_t & trkParts = trkAcc( *secVtx );
231  ntracks = trkParts.size();
232 
233  TLorentzVector sumP4(0,0,0,0);
234  double H = 0.0;
235  double HT = 0.0;
236  int charge = 0;
237  double minOpAng = -1.0* 1.e10;
238  double maxOpAng = 1.0* 1.e10;
239  double minD0 = 1.0* 1.e10;
240  double maxD0 = 0.0;
241  double maxDR = 0.0;
242 
243  xAOD::TrackParticle::ConstAccessor< std::vector< float > > accCovMatrixDiag( "definingParametersCovMatrixDiag" );
244 
245  ATH_MSG_DEBUG("Loop over tracks");
246  for(size_t t = 0; t < ntracks; t++){
247  if(!trkParts[t].isValid()){
248  ATH_MSG_DEBUG("Track " << t << " is bad!");
249  continue;
250  }
251  const xAOD::TrackParticle & trk = **trkParts[t];
252 
253  double trk_d0 = std::abs(trk.definingParameters()[0]);
254  double trk_z0 = std::abs(trk.definingParameters()[1]);
255 
256  if(trk_d0 < minD0){ minD0 = trk_d0; }
257  if(trk_d0 > maxD0){ maxD0 = trk_d0; }
258 
259  TLorentzVector vv;
260  // TODO: use values computed w.r.t SV
261  vv.SetPtEtaPhiM(trk.pt(),trk.eta(), trk.phi0(), trk.m());
262  sumP4 += vv;
263  H += vv.Vect().Mag();
264  HT += vv.Pt();
265 
266  TLorentzVector v_minus_iv(0,0,0,0);
267  for(size_t j = 0; j < ntracks; j++){
268  if (j == t){ continue; }
269  if(!trkParts[j].isValid()){
270  ATH_MSG_DEBUG("Track " << j << " is bad!");
271  continue;
272  }
273 
274  const xAOD::TrackParticle & trk_2 = **trkParts[j];
275 
276  TLorentzVector tmp;
277  // TODO: use values computed w.r.t. SV
278  tmp.SetPtEtaPhiM(trk_2.pt(),trk_2.eta(), trk_2.phi0(), trk_2.m());
279  v_minus_iv += tmp;
280 
281  if( j > t ) {
282  double tm = vv * tmp / ( vv.Mag() * tmp.Mag() );
283  if( minOpAng < tm ) minOpAng = tm;
284  if( maxOpAng > tm ) maxOpAng = tm;
285  }
286  }
287  double DR = vv.DeltaR(v_minus_iv);
288  if( DR > maxDR ){ maxDR = DR;}
289 
290  charge += trk.charge();
291 
292  xAOD::TrackParticle::ConstAccessor<float> Trk_Chi2("chiSquared");
293  xAOD::TrackParticle::ConstAccessor<float> Trk_nDoF("numberDoF");
294 
295  if ( Trk_Chi2.isAvailable(trk) && Trk_Chi2(trk) && Trk_nDoF.isAvailable(trk) && Trk_nDoF(trk) ) {
296  hist("RecoVertex/" + matchType + "_Trk_Chi2")->Fill(Trk_Chi2(trk) / Trk_nDoF(trk));
297  hist("RecoVertex/" + matchType + "_Trk_nDoF")->Fill(Trk_nDoF(trk));
298  }
299  hist("RecoVertex/" + matchType + "_Trk_D0")->Fill(trk_d0);
300  hist("RecoVertex/" + matchType + "_Trk_Z0")->Fill(trk_z0);
301  hist("RecoVertex/" + matchType + "_Trk_theta")->Fill(trk.definingParameters()[3]);
302  hist("RecoVertex/" + matchType + "_Trk_qOverP")->Fill(trk.definingParameters()[4]);
303  hist("RecoVertex/" + matchType + "_Trk_Eta")->Fill(trk.eta());
304  hist("RecoVertex/" + matchType + "_Trk_Phi")->Fill(trk.phi0());
305  hist("RecoVertex/" + matchType + "_Trk_E")->Fill(trk.e() / GeV);
306  hist("RecoVertex/" + matchType + "_Trk_M")->Fill(trk.m() / GeV);
307  hist("RecoVertex/" + matchType + "_Trk_Pt")->Fill(trk.pt() / GeV);
308  hist("RecoVertex/" + matchType + "_Trk_Px")->Fill(trk.p4().Px() / GeV);
309  hist("RecoVertex/" + matchType + "_Trk_Py")->Fill(trk.p4().Py() / GeV);
310  hist("RecoVertex/" + matchType + "_Trk_Pz")->Fill(trk.p4().Pz() / GeV);
311  hist("RecoVertex/" + matchType + "_Trk_charge")->Fill(trk.charge());
312  hist("RecoVertex/" + matchType + "_Trk_errD0")->Fill(trk.definingParametersCovMatrix()(0,0));
313  hist("RecoVertex/" + matchType + "_Trk_errZ0")->Fill(trk.definingParametersCovMatrix()(1,1));
314  } // end loop over tracks
315 
316  const double dir = sumP4.Vect().Dot( reco_pos ) / sumP4.Vect().Mag() / reco_pos.Mag();
317 
318  xAOD::Vertex::ConstAccessor<float> Chi2("chiSquared");
319  xAOD::Vertex::ConstAccessor<float> nDoF("numberDoF");
320 
321  hist("RecoVertex/" + matchType + "_x")->Fill(secVtx->x());
322  hist("RecoVertex/" + matchType + "_y")->Fill(secVtx->y());
323  hist("RecoVertex/" + matchType + "_z")->Fill(secVtx->z());
324  hist("RecoVertex/" + matchType + "_Lxy")->Fill(Lxy);
325  hist("RecoVertex/" + matchType + "_ntrk")->Fill(ntracks);
326  hist("RecoVertex/" + matchType + "_pT")->Fill(sumP4.Pt() / GeV);
327  hist("RecoVertex/" + matchType + "_eta")->Fill(sumP4.Eta());
328  hist("RecoVertex/" + matchType + "_phi")->Fill(sumP4.Phi());
329  hist("RecoVertex/" + matchType + "_mass")->Fill(sumP4.M() / GeV);
330  hist("RecoVertex/" + matchType + "_mu")->Fill(sumP4.M()/maxDR / GeV);
331  hist("RecoVertex/" + matchType + "_chi2")->Fill(Chi2(*secVtx)/nDoF(*secVtx));
332  hist("RecoVertex/" + matchType + "_dir")->Fill(dir);
333  hist("RecoVertex/" + matchType + "_charge")->Fill(charge);
334  hist("RecoVertex/" + matchType + "_H")->Fill(H / GeV);
335  hist("RecoVertex/" + matchType + "_HT")->Fill(HT / GeV);
336  hist("RecoVertex/" + matchType + "_minOpAng")->Fill(minOpAng);
337  hist("RecoVertex/" + matchType + "_maxOpAng")->Fill(maxOpAng);
338  hist("RecoVertex/" + matchType + "_mind0")->Fill(minD0);
339  hist("RecoVertex/" + matchType + "_maxd0")->Fill(maxD0);
340  hist("RecoVertex/" + matchType + "_maxdR")->Fill(maxDR);
341 
342  std::vector<InDetSecVtxTruthMatchUtils::VertexTruthMatchInfo> truthmatchinfo;
343  truthmatchinfo = matchInfoDecor(*secVtx);
344 
345  // This includes all matched vertices, including splits
346  if (matchType != "All" and matchType != "Fake") {
347  if(not truthmatchinfo.empty()){
348  float matchScore_weight = std::get<1>(truthmatchinfo.at(0));
349  float matchScore_pt = std::get<2>(truthmatchinfo.at(0));
350 
351  ATH_MSG_DEBUG("Match Score and probability: " << matchScore_weight << " " << matchScore_pt/0.01);
352 
353  const ElementLink<xAOD::TruthVertexContainer>& truthVertexLink = std::get<0>(truthmatchinfo.at(0));
354  const xAOD::TruthVertex& truthVtx = **truthVertexLink ;
355 
356  hist("RecoVertex/" + matchType + "_positionRes_R")->Fill(Lxy - truthVtx.perp());
357  hist("RecoVertex/" + matchType + "_positionRes_Z")->Fill(secVtx->z() - truthVtx.z());
358  hist("RecoVertex/" + matchType + "_matchScore_weight")->Fill(matchScore_weight);
359  hist("RecoVertex/" + matchType + "_matchScore_pt")->Fill(matchScore_pt);
360  }
361  }
362  }
363 
364  void SecVertexTruthMatchAlg::fillTruthHistograms(const xAOD::TruthVertex* truthVtx, const std::string& truthType) {
365 
366  hist("TruthVertex/" + truthType + "_x")->Fill(truthVtx->x());
367  hist("TruthVertex/" + truthType + "_y")->Fill(truthVtx->y());
368  hist("TruthVertex/" + truthType + "_z")->Fill(truthVtx->z());
369  hist("TruthVertex/" + truthType + "_R")->Fill(truthVtx->perp());
370  hist("TruthVertex/" + truthType + "_Eta")->Fill(truthVtx->eta());
371  hist("TruthVertex/" + truthType + "_Phi")->Fill(truthVtx->phi());
372  hist("TruthVertex/" + truthType + "_Ntrk_out")->Fill(truthVtx->nOutgoingParticles());
373 
374  ATH_MSG_DEBUG("Plotting truth parent");
375  const xAOD::TruthParticle& truthPart = *truthVtx->incomingParticle(0);
376 
377  hist("TruthVertex/" + truthType + "_Parent_E")->Fill(truthPart.e() / GeV);
378  hist("TruthVertex/" + truthType + "_Parent_M")->Fill(truthPart.m() / GeV);
379  hist("TruthVertex/" + truthType + "_Parent_Pt")->Fill(truthPart.pt() / GeV);
380  hist("TruthVertex/" + truthType + "_Parent_Phi")->Fill(truthPart.phi());
381  hist("TruthVertex/" + truthType + "_Parent_Eta")->Fill(truthPart.eta());
382  hist("TruthVertex/" + truthType + "_Parent_charge")->Fill(truthPart.charge());
383 
384  ATH_MSG_DEBUG("Plotting truth prod vtx");
385  if(truthPart.hasProdVtx()){
386  const xAOD::TruthVertex & vertex = *truthPart.prodVtx();
387 
388  hist("TruthVertex/" + truthType + "_ParentProdX")->Fill(vertex.x());
389  hist("TruthVertex/" + truthType + "_ParentProdY")->Fill(vertex.y());
390  hist("TruthVertex/" + truthType + "_ParentProdZ")->Fill(vertex.z());
391  hist("TruthVertex/" + truthType + "_ParentProdR")->Fill(vertex.perp());
392  hist("TruthVertex/" + truthType + "_ParentProdEta")->Fill(vertex.eta());
393  hist("TruthVertex/" + truthType + "_ParentProdPhi")->Fill(vertex.phi());
394  }
395  // m_truthInclusive_r->Fill(truthVtx.perp());
396 
397  // if(matchTypeDecor(truthVtx) >= RECONSTRUCTABLE){
398  // m_truthReconstructable_r->Fill(truthVtx.perp());
399  // }
400  // if(matchTypeDecor(truthVtx) >= ACCEPTED){
401  // m_truthAccepted_r->Fill(truthVtx.perp());
402  // }
403  // if(matchTypeDecor(truthVtx) >= SEEDED){
404  // m_truthSeeded_r->Fill(truthVtx.perp());
405  // }
406  // if(matchTypeDecor(truthVtx) >= RECONSTRUCTED){
407  // m_truthReconstructed_r->Fill(truthVtx.perp());
408  // }
409  // if(matchTypeDecor(truthVtx) >= RECONSTRUCTEDSPLIT){
410  // m_truthSplit_r->Fill(truthVtx.perp());
411  // }
412  //
413  }
414 } // namespace CP
xAOD::TruthVertex_v1::nOutgoingParticles
size_t nOutgoingParticles() const
Get the number of outgoing particles.
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
xAOD::Vertex_v1::x
float x() const
Returns the x position.
xAOD::TrackParticle_v1::m
virtual double m() const override final
The invariant mass of the particle..
Definition: TrackParticle_v1.cxx:83
GeV
const float GeV
Definition: SecVertexTruthMatchAlg.cxx:13
xAOD::TruthVertex_v1::phi
float phi() const
Vertex azimuthal angle.
Definition: TruthVertex_v1.cxx:176
SecVertexTruthMatchAlg.h
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.
AthHistogramming::book
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
Definition: AthHistogramming.h:303
InDetSecVtxTruthMatchUtils::isFake
bool isFake(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:60
xAOD::TrackParticle_v1::charge
float charge() const
Returns the charge.
Definition: TrackParticle_v1.cxx:150
InDetSecVtxTruthMatchUtils::isReconstructable
bool isReconstructable(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:69
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
AthHistogramming::efficiency
TEfficiency * efficiency(const std::string &effName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TEfficiency.
Definition: AthHistogramming.cxx:250
InDetSecVtxTruthMatchUtils::isMerged
bool isMerged(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:52
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
InDetSecVtxTruthMatchUtils::isMatched
bool isMatched(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:48
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
InDetSecVtxTruthMatchUtils::isSplit
bool isSplit(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:56
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:225
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
xAOD::TruthVertex_v1::y
float y() const
Vertex y displacement.
xAOD::VxType::VertexType
VertexType
Vertex types.
Definition: TrackingPrimitives.h:569
CP::SecVertexTruthMatchAlg::m_matchTool
ToolHandle< IInDetSecVtxTruthMatchTool > m_matchTool
Definition: SecVertexTruthMatchAlg.h:54
xAOD::TrackParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition: TrackParticle_v1.cxx:129
InDetSecVtxTruthMatchTool.h
H
#define H(x, y, z)
Definition: MD5.cxx:114
CP::SecVertexTruthMatchAlg::fillTruthHistograms
void fillTruthHistograms(const xAOD::TruthVertex *truthVtx, const std::string &truthType)
Definition: SecVertexTruthMatchAlg.cxx:364
CP::SecVertexTruthMatchAlg::m_writeHistograms
Gaudi::Property< bool > m_writeHistograms
Definition: SecVertexTruthMatchAlg.h:52
InDetSecVtxTruthMatchUtils::isOther
bool isOther(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:64
InDetSecVtxTruthMatchUtils::isReconstructed
bool isReconstructed(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:81
xAOD::TruthParticle_v1::e
virtual double e() const override final
The total energy of the particle.
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
CP::SecVertexTruthMatchAlg::initialize
virtual StatusCode initialize() override
Definition: SecVertexTruthMatchAlg.cxx:20
InDetSecVtxTruthMatchUtils::isAccepted
bool isAccepted(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:73
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::VxType::SecVtx
@ SecVtx
Secondary vertex.
Definition: TrackingPrimitives.h:572
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
CP::SecVertexTruthMatchAlg::m_secVtxContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_secVtxContainerKey
Definition: SecVertexTruthMatchAlg.h:41
CP::SecVertexTruthMatchAlg::m_targetPDGIDs
Gaudi::Property< std::vector< int > > m_targetPDGIDs
Definition: SecVertexTruthMatchAlg.h:50
xAOD::TruthVertex_v1::perp
float perp() const
Vertex transverse distance from the beam line.
Definition: TruthVertex_v1.cxx:163
xAOD::TruthParticle_v1::hasProdVtx
bool hasProdVtx() const
Check for a production vertex on this particle.
Definition: TruthParticle_v1.cxx:74
CP::SecVertexTruthMatchAlg::execute
virtual StatusCode execute() override
Definition: SecVertexTruthMatchAlg.cxx:121
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
xAOD::Vertex_v1::TrackParticleLinks_t
std::vector< ElementLink< xAOD::TrackParticleContainer > > TrackParticleLinks_t
Type for the associated track particles.
Definition: Vertex_v1.h:128
xAOD::Vertex_v1::z
float z() const
Returns the z position.
xAOD::TruthVertex_v1::incomingParticle
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
Definition: TruthVertex_v1.cxx:69
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
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
CP::GeV
const double GeV
Definition: EgammaCalibrationAndSmearingTool.cxx:42
beamspotman.dir
string dir
Definition: beamspotman.py:623
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
xAOD::TrackParticle_v1::phi0
float phi0() const
Returns the parameter, which has range to .
Definition: TrackParticle_v1.cxx:158
xAOD::TrackParticle_v1::definingParametersCovMatrix
const ParametersCovMatrix_t definingParametersCovMatrix() const
Returns the 5x5 symmetric matrix containing the defining parameters covariance matrix.
Definition: TrackParticle_v1.cxx:246
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CP::SecVertexTruthMatchAlg::fillRecoHistograms
void fillRecoHistograms(const xAOD::Vertex *secVtx, const std::string &matchType)
Definition: SecVertexTruthMatchAlg.cxx:217
charge
double charge(const T &p)
Definition: AtlasPID.h:538
xAOD::TrackParticle_v1::e
virtual double e() const override final
The total energy of the particle.
Definition: TrackParticle_v1.cxx:109
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
xAOD::TrackParticle_v1::definingParameters
DefiningParameters_t definingParameters() const
Returns a SVector of the Perigee track parameters.
Definition: TrackParticle_v1.cxx:171
xAOD::TruthVertex_v1::x
float x() const
Vertex x displacement.
CP::SecVertexTruthMatchAlg::SecVertexTruthMatchAlg
SecVertexTruthMatchAlg(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: SecVertexTruthMatchAlg.cxx:17
InDetSecVtxTruthMatchUtils::isReconstructedSplit
bool isReconstructedSplit(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:85
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::TruthVertex_v1::eta
float eta() const
Vertex pseudorapidity.
Definition: TruthVertex_v1.cxx:170
xAOD::TruthParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
Definition: TruthParticle_v1.cxx:181
xAOD::TruthVertex_v1::z
float z() const
Vertex longitudinal distance along the beam line form the origin.
xAOD::Vertex_v1::y
float y() const
Returns the y position.
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
AthHistogramming::hist
TH1 * hist(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.
Definition: AthHistogramming.cxx:198
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
CP::SecVertexTruthMatchAlg::m_truthVtxContainerKey
SG::ReadHandleKey< xAOD::TruthVertexContainer > m_truthVtxContainerKey
Definition: SecVertexTruthMatchAlg.h:44
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TruthParticle.h
InDetSecVtxTruthMatchUtils::isSeeded
bool isSeeded(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:77
PlotCalibFromCool.vv
vv
Definition: PlotCalibFromCool.py:716
CP::SecVertexTruthMatchAlg::m_trackParticleContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleContainerKey
Definition: SecVertexTruthMatchAlg.h:47
xAOD::TruthParticle_v1::m
virtual double m() const override final
The mass of the particle.
xAOD::TruthParticle_v1::charge
double charge() const
Physical charge.