CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VertexNTupler.cc
Go to the documentation of this file.
2 #include "TObjString.h"
31 
32 #include "TTree.h"
33 
34 #include <map>
35 #include <string>
36 #include <vector>
37 #include <iostream>
38 
39 using namespace std;
40 
41 namespace l1tVertexFinder {
42 
43  class VertexNTupler : public edm::EDAnalyzer {
44  public:
45  explicit VertexNTupler(const edm::ParameterSet&);
46  ~VertexNTupler() override;
47 
48  private:
50  std::vector<float> energy;
51  std::vector<float> pt;
52  std::vector<float> eta;
53  std::vector<float> phi;
54 
55  void clear() {
56  energy.clear();
57  pt.clear();
58  eta.clear();
59  phi.clear();
60  }
61  };
62 
64  std::vector<float> energy;
65  std::vector<float> pt;
66  std::vector<float> eta;
67  std::vector<float> phi;
68  std::vector<int> pdgId;
69  std::vector<int> status;
70 
71  void clear() {
72  energy.clear();
73  pt.clear();
74  eta.clear();
75  phi.clear();
76  pdgId.clear();
77  status.clear();
78  }
79  };
80 
82  std::vector<unsigned> numTracks;
83  std::vector<std::vector<unsigned>> trackIdxs;
84  std::vector<float> z0;
85  std::vector<float> sumPt;
86 
87  void clear() {
88  numTracks.clear();
89  trackIdxs.clear();
90  z0.clear();
91  sumPt.clear();
92  }
93  };
94 
96  std::vector<float> pt;
97  std::vector<float> eta;
98  std::vector<float> phi;
99  std::vector<float> z0;
100  std::vector<unsigned> numStubs;
101  std::vector<float> chi2dof;
102  std::vector<int> trueMatchIdx;
103  std::vector<int> truthMapMatchIdx;
104  std::vector<float> truthMapIsGenuine;
105  std::vector<float> truthMapIsLooselyGenuine;
106  std::vector<float> truthMapIsCombinatoric;
107  std::vector<float> truthMapIsUnknown;
108 
109  void clear() {
110  pt.clear();
111  eta.clear();
112  phi.clear();
113  z0.clear();
114  numStubs.clear();
115  chi2dof.clear();
116  trueMatchIdx.clear();
117  truthMapMatchIdx.clear();
118  truthMapIsGenuine.clear();
119  truthMapIsLooselyGenuine.clear();
120  truthMapIsCombinatoric.clear();
121  truthMapIsUnknown.clear();
122  }
123  };
124 
126  std::vector<float> pt;
127  std::vector<float> eta;
128  std::vector<float> phi;
129  std::vector<float> z0;
130  std::vector<int> pdgId;
131  std::vector<float> physCollision;
132  std::vector<float> use;
133  std::vector<float> useForEff;
134  std::vector<float> useForAlgEff;
135  std::vector<float> useForVertexReco;
136 
137  void clear() {
138  pt.clear();
139  eta.clear();
140  phi.clear();
141  z0.clear();
142  pdgId.clear();
143  physCollision.clear();
144  use.clear();
145  useForEff.clear();
146  useForAlgEff.clear();
147  useForVertexReco.clear();
148  }
149  };
150 
151  void beginJob() override;
152  void analyze(const edm::Event& evt, const edm::EventSetup& setup) override;
153  void endJob() override;
154 
155  // define types for stub-related classes
158 
159  // references to tags containing information relevant to perofrmance analysis
166  std::map<std::string, edm::EDGetTokenT<TTTrackCollectionView>> l1TracksTokenMap_;
167  std::map<std::string, edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>> l1TracksMapTokenMap_;
168  std::map<std::string, edm::EDGetTokenT<std::vector<l1t::Vertex>>> l1VerticesTokenMap_;
169  std::map<std::string, edm::EDGetTokenT<std::vector<l1t::Vertex>>> l1VerticesExtraTokenMap_;
170  std::vector<edm::EDGetTokenT<std::vector<l1t::Vertex>>> l1VerticesExtraTokens_;
171 
172  TTree* outputTree_;
173 
174  const bool printResults_;
175 
176  // storage class for configuration parameters
178 
179  //edm::Service<TFileService> fs_;
180 
181  // Histograms for Vertex Reconstruction
182 
183  float numTrueInteractions_, hepMCVtxZ0_, genVtxZ0_;
185 
188  std::vector<float> truePileUpVtxZ0_;
190 
191  std::map<std::string, RecoTracksBranchData> l1TracksBranchData_;
192  std::map<std::string, RecoVerticesBranchData> l1VerticesBranchData_;
193  std::map<std::string, std::string> l1VerticesInputMap_;
194 
195  std::unordered_map<std::string, std::vector<unsigned>> l1Vertices_branchMap_numTracks_;
196  std::unordered_map<std::string, std::vector<float>> l1Vertices_branchMap_z0_;
197  std::unordered_map<std::string, std::vector<float>> l1Vertices_branchMap_z0_etaWeighted_;
198  std::unordered_map<std::string, std::vector<float>> l1Vertices_branchMap_sumPt_;
199 
200  std::vector<std::vector<unsigned>> l1Vertices_extra_numTracks_;
201  std::vector<std::vector<float>> l1Vertices_extra_z0_;
202  std::vector<std::vector<float>> l1Vertices_extra_z0_etaWeighted_;
203  std::vector<std::vector<float>> l1Vertices_extra_sumPt_;
204 
205  bool available_; // ROOT file for histograms is open.
206  };
207 
208  VertexNTupler::VertexNTupler(const edm::ParameterSet& iConfig)
209  : inputDataToken_(consumes<l1tVertexFinder::InputData>(iConfig.getParameter<edm::InputTag>("inputDataInputTag"))),
210  pileupSummaryToken_(consumes<std::vector<PileupSummaryInfo>>(edm::InputTag("addPileupInfo"))),
211  genParticlesToken_(
212  consumes<edm::View<reco::GenParticle>>(iConfig.getParameter<edm::InputTag>("genParticleInputTag"))),
213  genJetsToken_(consumes<std::vector<reco::GenJet>>(iConfig.getParameter<edm::InputTag>("genJetsInputTag"))),
214  allMatchedTPsToken_(
215  consumes<std::vector<l1tVertexFinder::TP>>(iConfig.getParameter<edm::InputTag>("l1TracksTPInputTags"))),
216  vTPsToken_(consumes<edm::ValueMap<l1tVertexFinder::TP>>(
217  iConfig.getParameter<edm::InputTag>("l1TracksTPValueMapInputTags"))),
218  //outputTree_(fs_->make<TTree>("l1VertexReco", "L1 vertex-related info")),
219  printResults_(iConfig.getParameter<bool>("printResults")),
220  settings_(iConfig) {
221  const std::vector<std::string> trackBranchNames(
222  iConfig.getParameter<std::vector<std::string>>("l1TracksBranchNames"));
223  const std::vector<edm::InputTag> trackInputTags(
224  iConfig.getParameter<std::vector<edm::InputTag>>("l1TracksInputTags"));
225  const std::vector<edm::InputTag> trackMapInputTags(
226  iConfig.getParameter<std::vector<edm::InputTag>>("l1TracksTruthMapInputTags"));
227 
229  available_ = fs_.isAvailable();
230  if (not available_)
231  return; // No ROOT file open.
232 
233  outputTree_ = fs_->make<TTree>("l1VertexReco", "L1 vertex-related info");
234 
235  if (trackBranchNames.size() != trackInputTags.size())
236  throw cms::Exception("The number of track branch names (" + std::to_string(trackBranchNames.size()) +
237  ") specified in the config does not match the number of input tags (" +
238  std::to_string(trackInputTags.size()) + ")");
239  if (trackBranchNames.size() != trackMapInputTags.size())
240  throw cms::Exception("The number of track branch names (" + std::to_string(trackBranchNames.size()) +
241  ") specified in the config does not match the number of track map input tags (" +
242  std::to_string(trackMapInputTags.size()) + ")");
243 
244  const std::vector<std::string> vertexBranchNames(
245  iConfig.getParameter<std::vector<std::string>>("l1VertexBranchNames"));
246  const std::vector<edm::InputTag> vertexInputTags(
247  iConfig.getParameter<std::vector<edm::InputTag>>("l1VertexInputTags"));
248  const std::vector<std::string> vertexTrackNames(
249  iConfig.getParameter<std::vector<std::string>>("l1VertexTrackInputs"));
250 
251  if (vertexBranchNames.size() != vertexInputTags.size())
252  throw cms::Exception("The number of vertex branch names (" + std::to_string(vertexBranchNames.size()) +
253  ") specified in the config does not match the number of input tags (" +
254  std::to_string(vertexInputTags.size()) + ")");
255  if (vertexBranchNames.size() != vertexTrackNames.size())
256  throw cms::Exception(
257  "The number of vertex branch names (" + std::to_string(vertexBranchNames.size()) +
258  ") specified in the config does not match the number of associated input track collection names (" +
259  std::to_string(vertexTrackNames.size()) + ")");
260 
261  outputTree_->Branch("genJets_energy", &genJetsBranchData_.energy);
262  outputTree_->Branch("genJets_pt", &genJetsBranchData_.pt);
263  outputTree_->Branch("genJets_eta", &genJetsBranchData_.eta);
264  outputTree_->Branch("genJets_phi", &genJetsBranchData_.phi);
265  outputTree_->Branch("genParticles_hardProcOutgoing_energy", &genParticlesHardOutgoingBranchData_.energy);
266  outputTree_->Branch("genParticles_hardProcOutgoing_pt", &genParticlesHardOutgoingBranchData_.pt);
267  outputTree_->Branch("genParticles_hardProcOutgoing_eta", &genParticlesHardOutgoingBranchData_.eta);
268  outputTree_->Branch("genParticles_hardProcOutgoing_phi", &genParticlesHardOutgoingBranchData_.phi);
269  outputTree_->Branch("genParticles_hardProcOutgoing_pdgId", &genParticlesHardOutgoingBranchData_.pdgId);
270  outputTree_->Branch("genParticles_hardProcOutgoing_status", &genParticlesHardOutgoingBranchData_.status);
271  outputTree_->Branch("genVertex_z0", &genVtxZ0_);
272  outputTree_->Branch("hepMCVertex_z0", &hepMCVtxZ0_);
273  outputTree_->Branch("pileupSummary_trueNumInteractions", &numTrueInteractions_);
274  outputTree_->Branch("pileupSummary_numPileupVertices", &numPileupVertices_);
275 
276  std::vector<std::string>::const_iterator trackBranchNameIt = trackBranchNames.begin();
277  std::vector<edm::InputTag>::const_iterator trackInputTagIt = trackInputTags.begin();
278  std::vector<edm::InputTag>::const_iterator trackMapInputTagIt = trackMapInputTags.begin();
279  for (; trackBranchNameIt != trackBranchNames.end(); trackBranchNameIt++, trackInputTagIt++, trackMapInputTagIt++) {
280  l1TracksTokenMap_[*trackBranchNameIt] = consumes<TTTrackCollectionView>(*trackInputTagIt);
281  l1TracksMapTokenMap_[*trackBranchNameIt] =
282  consumes<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>(*trackMapInputTagIt);
283 
284  RecoTracksBranchData& branchData = l1TracksBranchData_[*trackBranchNameIt];
285 
286  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_pt").c_str(), &branchData.pt);
287  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_eta").c_str(), &branchData.eta);
288  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_phi").c_str(), &branchData.phi);
289  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_z0").c_str(), &branchData.z0);
290  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_numStubs").c_str(), &branchData.numStubs);
291  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_chi2dof").c_str(), &branchData.chi2dof);
292  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_trueMatchIdx").c_str(), &branchData.trueMatchIdx);
293  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_truthMap_matchIdx").c_str(),
294  &branchData.truthMapMatchIdx);
295  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_truthMap_isGenuine").c_str(),
296  &branchData.truthMapIsGenuine);
297  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_truthMap_isLooselyGenuine").c_str(),
298  &branchData.truthMapIsLooselyGenuine);
299  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_truthMap_isCombinatoric").c_str(),
300  &branchData.truthMapIsCombinatoric);
301  outputTree_->Branch(("recoTracks_" + *trackBranchNameIt + "_truthMap_isUnknown").c_str(),
302  &branchData.truthMapIsUnknown);
303  }
304 
305  std::vector<std::string>::const_iterator branchNameIt = vertexBranchNames.begin();
306  std::vector<edm::InputTag>::const_iterator inputTagIt = vertexInputTags.begin();
307  std::vector<std::string>::const_iterator l1VertexTrackNameIt = vertexTrackNames.begin();
308  for (; branchNameIt != vertexBranchNames.end(); branchNameIt++, inputTagIt++, l1VertexTrackNameIt++) {
309  l1VerticesTokenMap_[*branchNameIt] = consumes<std::vector<l1t::Vertex>>(*inputTagIt);
310 
312  RecoVerticesBranchData& branchData = l1VerticesBranchData_.at(*branchNameIt);
313  l1VerticesInputMap_[*branchNameIt] = *l1VertexTrackNameIt;
314 
315  if (l1TracksTokenMap_.count(*l1VertexTrackNameIt) == 0)
316  throw cms::Exception("Invalid track collection name '" + *l1VertexTrackNameIt +
317  "' specified as input to vertex collection '" + *branchNameIt + "'");
318 
319  outputTree_->Branch(("recoVertices_" + *branchNameIt + "_numTracks").c_str(), &branchData.numTracks);
320  outputTree_->Branch(("recoVertices_" + *branchNameIt + "_trackIdxs").c_str(), &branchData.trackIdxs);
321  outputTree_->Branch(("recoVertices_" + *branchNameIt + "_z0").c_str(), &branchData.z0);
322  outputTree_->Branch(("recoVertices_" + *branchNameIt + "_sumPt").c_str(), &branchData.sumPt);
323  }
324 
325  outputTree_->Branch("truePileUpVertices_z0", &truePileUpVtxZ0_);
326  outputTree_->Branch("trueTracks_pt", &trueTracksBranchData_.pt);
327  outputTree_->Branch("trueTracks_eta", &trueTracksBranchData_.eta);
328  outputTree_->Branch("trueTracks_phi", &trueTracksBranchData_.phi);
329  outputTree_->Branch("trueTracks_z0", &trueTracksBranchData_.z0);
330  outputTree_->Branch("trueTracks_pdgId", &trueTracksBranchData_.pdgId);
331  outputTree_->Branch("trueTracks_physCollision", &trueTracksBranchData_.physCollision);
332  outputTree_->Branch("trueTracks_use", &trueTracksBranchData_.use);
333  outputTree_->Branch("trueTracks_useForEff", &trueTracksBranchData_.useForEff);
334  outputTree_->Branch("trueTracks_useForAlgEff", &trueTracksBranchData_.useForAlgEff);
335  outputTree_->Branch("trueTracks_useForVtxReco", &trueTracksBranchData_.useForVertexReco);
336 
337  const std::vector<edm::InputTag> extraVertexInputTags(
338  iConfig.getParameter<std::vector<edm::InputTag>>("extraL1VertexInputTags"));
339  const std::vector<std::string> extraVertexDescriptions(
340  iConfig.getParameter<std::vector<std::string>>("extraL1VertexDescriptions"));
341  for (const auto& inputTag : extraVertexInputTags)
342  l1VerticesExtraTokens_.push_back(consumes<std::vector<l1t::Vertex>>(inputTag));
343  TObjArray* descriptionArray = new TObjArray();
344  for (const auto& description : extraVertexDescriptions)
345  descriptionArray->Add(new TObjString(description.c_str()));
346  outputTree_->GetUserInfo()->Add(descriptionArray);
347  outputTree_->Branch("vertices_extra_numTracks", &l1Vertices_extra_numTracks_);
348  outputTree_->Branch("vertices_extra_z0", &l1Vertices_extra_z0_);
349  outputTree_->Branch("vertices_extra_z0_etaWeighted", &l1Vertices_extra_z0_etaWeighted_);
350  outputTree_->Branch("vertices_extra_sumPt", &l1Vertices_extra_sumPt_);
351  }
352 
354 
355  std::ostream& operator<<(std::ostream& out, const reco::GenParticle& particle) {
356  const bool positive = (particle.pdgId() < 0);
357  const size_t absId = abs(particle.pdgId());
358  switch (absId) {
359  case 1:
360  return (out << (positive ? "d" : "anti-d"));
361  case 2:
362  return (out << (positive ? "u" : "anti-u"));
363  case 3:
364  return (out << (positive ? "s" : "anti-s"));
365  case 4:
366  return (out << (positive ? "c" : "anti-c"));
367  case 5:
368  return (out << (positive ? "b" : "anti-b"));
369  case 6:
370  return (out << (positive ? "t" : "anti-t"));
371  case 11:
372  return (out << (positive ? "e+" : "e-"));
373  case 12:
374  return (out << (positive ? "nu_e" : "anti-nu_e"));
375  case 13:
376  return (out << (positive ? "mu+" : "mu-"));
377  case 14:
378  return (out << (positive ? "nu_mu" : "anti-nu_mu"));
379  case 15:
380  return (out << (positive ? "tau+" : "tau-"));
381  case 16:
382  return (out << (positive ? "nu_tau" : "anti-nu_tau"));
383  case 21:
384  return (out << "g");
385  case 22:
386  return (out << "photon");
387  case 23:
388  return (out << "Z");
389  case 24:
390  return (out << (positive ? "W-" : "W+"));
391  default:
392  if ((((absId / 1000) % 10) != 0) and (((absId / 10) % 10) == 0))
393  return (out << "diquark<" << particle.pdgId() << ">");
394  else
395  return (out << "unknown<" << particle.pdgId() << ">");
396  }
397  }
398 
400  // Note useful info about MC truth particles and about reconstructed stubs
402  iEvent.getByToken(inputDataToken_, inputDataHandle);
403  InputData inputData = *inputDataHandle;
404 
405  edm::Handle<edm::ValueMap<TP>> tpValueMapHandle;
406  iEvent.getByToken(vTPsToken_, tpValueMapHandle);
407  edm::ValueMap<TP> tpValueMap = *tpValueMapHandle;
408 
409  // Create collections to hold the desired objects
410  std::map<std::string, std::vector<L1TrackTruthMatched>> l1TrackCollections;
411  std::map<std::string, edm::Handle<TTTrackAssMap>> truthAssocMapHandles;
412 
413  // Create iterators for the maps
414  auto tokenMapEntry = l1TracksTokenMap_.begin(), tokenMapEntryEnd = l1TracksTokenMap_.end();
415  auto mapTokenMapEntry = l1TracksMapTokenMap_.begin(), mapTokenMapEntryEnd = l1TracksMapTokenMap_.end();
416 
417  // Iterate over the maps
418  for (; (tokenMapEntry != tokenMapEntryEnd) && (mapTokenMapEntry != mapTokenMapEntryEnd);
419  ++tokenMapEntry, ++mapTokenMapEntry) {
420  edm::Handle<TTTrackCollectionView> l1TracksHandle;
421  edm::Handle<TTTrackAssMap>& mcTruthTTTrackHandle = truthAssocMapHandles[mapTokenMapEntry->first];
422  iEvent.getByToken(tokenMapEntry->second, l1TracksHandle);
423  iEvent.getByToken(l1TracksMapTokenMap_.at(mapTokenMapEntry->first), mcTruthTTTrackHandle);
424 
425  std::vector<L1TrackTruthMatched>& l1Tracks = l1TrackCollections[tokenMapEntry->first];
426  l1Tracks.reserve(l1TracksHandle->size());
427  for (const auto& track : l1TracksHandle->ptrs()) {
428  l1Tracks.push_back(L1TrackTruthMatched(track, inputData.getTPPtrToRefMap(), tpValueMap, mcTruthTTTrackHandle));
429  }
430  }
431 
432  // create a map for associating fat reco tracks with their underlying
433  // TTTrack pointers
434  std::map<std::string, std::map<const edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, const L1TrackTruthMatched*>>
435  edmL1TrackMaps;
436 
437  // get a list of reconstructed tracks with references to their TPs
438  for (const auto& entry : l1TrackCollections) {
439  auto& edmL1Map = edmL1TrackMaps[entry.first];
440  for (const auto& track : entry.second) {
441  edmL1Map.insert(std::pair<const edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, const L1TrackTruthMatched*>(
442  track.getTTTrackPtr(), &track));
443  }
444  }
445 
447 
448  // Pile-up summary info
450  iEvent.getByToken(pileupSummaryToken_, pileupHandle);
451 
452  for (auto bxIt = pileupHandle->begin(); bxIt != pileupHandle->end(); bxIt++) {
453  if (bxIt->getBunchCrossing() == 0) {
454  numTrueInteractions_ = bxIt->getTrueNumInteractions();
455  numPileupVertices_ = bxIt->getPU_NumInteractions();
456  }
457  }
458 
459  // True track info
462  iEvent.getByToken(allMatchedTPsToken_, allMatchedTPsHandle);
463 
464  for (const auto& tp : *allMatchedTPsHandle) {
465  trueTracksBranchData_.pt.push_back(tp->pt());
466  trueTracksBranchData_.eta.push_back(tp->eta());
467  trueTracksBranchData_.phi.push_back(tp->phi());
468  trueTracksBranchData_.z0.push_back(tp->z0());
469  trueTracksBranchData_.pdgId.push_back(tp->pdgId());
470  trueTracksBranchData_.physCollision.push_back(tp.physicsCollision() ? 1.0 : 0.0);
471  trueTracksBranchData_.use.push_back(tp.use() ? 1.0 : 0.0);
472  trueTracksBranchData_.useForEff.push_back(tp.useForEff() ? 1.0 : 0.0);
473  trueTracksBranchData_.useForAlgEff.push_back(tp.useForAlgEff() ? 1.0 : 0.0);
474  trueTracksBranchData_.useForVertexReco.push_back(tp.useForVertexReco() ? 1.0 : 0.0);
475  }
476 
477  // True pile-up vertex info
478  truePileUpVtxZ0_.clear();
479  for (const Vertex& vtx : inputData.getPileUpVertices())
480  truePileUpVtxZ0_.push_back(vtx.z0());
481 
482  // Generator level vertex info
483  hepMCVtxZ0_ = inputData.getHepMCVertex().vz();
484  genVtxZ0_ = inputData.getGenVertex().vz();
485 
486  // Gen particles
489  iEvent.getByToken(genParticlesToken_, genParticlesH);
490  for (const auto& p : *genParticlesH) {
491  genParticlesHardOutgoingBranchData_.energy.push_back(p.energy());
492  genParticlesHardOutgoingBranchData_.pt.push_back(p.pt());
493  genParticlesHardOutgoingBranchData_.eta.push_back(p.eta());
494  genParticlesHardOutgoingBranchData_.phi.push_back(p.phi());
495  genParticlesHardOutgoingBranchData_.pdgId.push_back(p.pdgId());
496  genParticlesHardOutgoingBranchData_.status.push_back(p.status());
497  }
498 
499  // Gen jet (AK4) branches
502  iEvent.getByToken(genJetsToken_, genJetsHandle);
503  for (const auto& genJet : *genJetsHandle) {
504  genJetsBranchData_.energy.push_back(genJet.energy());
505  genJetsBranchData_.pt.push_back(genJet.pt());
506  genJetsBranchData_.eta.push_back(genJet.eta());
507  genJetsBranchData_.phi.push_back(genJet.phi());
508  }
509 
510  for (const auto& entry : l1TrackCollections) {
511  const auto& l1Tracks = entry.second;
512  RecoTracksBranchData& branchData = l1TracksBranchData_.at(entry.first);
513 
514  const TTTrackAssociationMap<Ref_Phase2TrackerDigi_>& truthAssocMap = *truthAssocMapHandles.at(entry.first);
515 
516  // Reco track branches
517  branchData.clear();
518  for (const L1TrackTruthMatched& track : l1Tracks) {
519  branchData.pt.push_back(track.pt());
520  branchData.eta.push_back(track.eta());
521  branchData.phi.push_back(track.phi0());
522  branchData.z0.push_back(track.z0());
523  branchData.numStubs.push_back(track.getNumStubs());
524  branchData.chi2dof.push_back(track.chi2dof());
525  branchData.trueMatchIdx.push_back(track.getMatchedTPidx());
526 
527  edm::Ptr<TrackingParticle> matchedTP = truthAssocMap.findTrackingParticlePtr(track.getTTTrackPtr());
528  if (matchedTP.isNull())
529  branchData.truthMapMatchIdx.push_back(-1);
530  else {
531  auto it = std::find_if(allMatchedTPsHandle->begin(),
532  allMatchedTPsHandle->end(),
533  [&matchedTP](auto const& tp) { return tp.getTrackingParticle() == matchedTP; });
534  assert(it != allMatchedTPsHandle->end());
535  branchData.truthMapMatchIdx.push_back(std::distance(allMatchedTPsHandle->begin(), it));
536  }
537  branchData.truthMapIsGenuine.push_back(truthAssocMap.isGenuine(track.getTTTrackPtr()) ? 1.0 : 0.0);
538  branchData.truthMapIsLooselyGenuine.push_back(truthAssocMap.isLooselyGenuine(track.getTTTrackPtr()) ? 1.0
539  : 0.0);
540  branchData.truthMapIsCombinatoric.push_back(truthAssocMap.isCombinatoric(track.getTTTrackPtr()) ? 1.0 : 0.0);
541  branchData.truthMapIsUnknown.push_back(truthAssocMap.isUnknown(track.getTTTrackPtr()) ? 1.0 : 0.0);
542  }
543  }
544 
545  // Reco vertex branches
546  for (const auto& tokenMapEntry : l1VerticesTokenMap_) {
547  RecoVerticesBranchData& branchData = l1VerticesBranchData_.at(tokenMapEntry.first);
548 
550  iEvent.getByToken(tokenMapEntry.second, handle);
551  std::vector<std::shared_ptr<const RecoVertexWithTP>> recoVertices;
552  recoVertices.reserve(handle->size());
553  for (unsigned int i = 0; i < handle->size(); ++i) {
554  recoVertices.push_back(std::shared_ptr<const RecoVertexWithTP>(
555  new RecoVertexWithTP(handle->at(i), edmL1TrackMaps.at(l1VerticesInputMap_.at(tokenMapEntry.first)))));
556  }
557 
558  branchData.clear();
559  std::vector<L1TrackTruthMatched>& l1Tracks = l1TrackCollections.at(l1VerticesInputMap_.at(tokenMapEntry.first));
560  for (const std::shared_ptr<const RecoVertexWithTP>& vtx : recoVertices) {
561  branchData.numTracks.push_back(vtx->numTracks());
562  branchData.trackIdxs.push_back(std::vector<unsigned>());
563  for (const L1TrackTruthMatched* track : vtx->tracks())
564  branchData.trackIdxs.back().push_back(track - l1Tracks.data());
565  branchData.z0.push_back(vtx->z0());
566  branchData.sumPt.push_back(vtx->pt());
567  }
568 
569  if (printResults_) {
570  edm::LogInfo("VertexNTupler") << "analyze::" << recoVertices.size() << " '" << tokenMapEntry.first
571  << "' vertices were found ... ";
572  for (const auto& vtx : recoVertices) {
573  edm::LogInfo("VertexNTupler") << "analyze::"
574  << " * z0 = " << vtx->z0() << "; contains " << vtx->numTracks()
575  << " tracks ...";
576  for (const auto& trackPtr : vtx->tracks())
577  edm::LogInfo("VertexNTupler") << "analyze::"
578  << " - z0 = " << trackPtr->z0() << "; pt = " << trackPtr->pt()
579  << ", eta = " << trackPtr->eta() << ", phi = " << trackPtr->phi0();
580  }
581  }
582  }
583 
588 
589  for (size_t i = 0; i < l1VerticesExtraTokens_.size(); i++) {
591  iEvent.getByToken(l1VerticesExtraTokens_.at(i), vertexHandle);
592 
593  const std::vector<l1t::Vertex>& vertices = *vertexHandle;
594 
595  l1Vertices_extra_numTracks_.at(i).clear();
596  l1Vertices_extra_z0_.at(i).clear();
598  l1Vertices_extra_sumPt_.at(i).clear();
599 
600  for (const auto& vertex : vertices) {
601  l1Vertices_extra_numTracks_.at(i).push_back(vertex.tracks().size());
602  l1Vertices_extra_z0_.at(i).push_back(vertex.z0());
603 
604  float sumPt = 0.0;
605  float etaWeightedSumZ0 = 0.0;
606  float etaWeightSum = 0.0;
607  for (const auto& track : vertex.tracks()) {
608  sumPt += track->momentum().transverse();
609  // const float zRes = 0.133616 * track->momentum().eta() * track->momentum().eta() - 0.0522353 * std::abs(track->momentum().eta()) + 0.109918;
610  const float zRes = 0.223074 * track->momentum().eta() * track->momentum().eta() -
611  0.050231 * abs(track->momentum().eta()) + 0.209719;
612  etaWeightedSumZ0 += track->POCA().z() / (zRes * zRes);
613  etaWeightSum += 1.0 / (zRes * zRes);
614  }
615 
616  l1Vertices_extra_sumPt_.at(i).push_back(sumPt);
617  l1Vertices_extra_z0_etaWeighted_.at(i).push_back(etaWeightedSumZ0 / etaWeightSum);
618  }
619  }
620 
621  outputTree_->Fill();
623 
624  if (settings_.debug() > 2)
625  edm::LogInfo("VertexNTupler") << "analyze::================ End of Event ==============";
626  }
627 
629 
631 
632 } // namespace l1tVertexFinder
633 
634 using namespace l1tVertexFinder;
635 
636 // define this as a plug-in
const edm::EDGetTokenT< edm::View< reco::GenParticle > > genParticlesToken_
std::vector< std::vector< unsigned > > l1Vertices_extra_numTracks_
std::vector< edm::EDGetTokenT< std::vector< l1t::Vertex > > > l1VerticesExtraTokens_
std::vector< std::vector< float > > l1Vertices_extra_z0_
double vz() const
Vertex z position [cm].
Definition: Vertex.h:38
std::vector< std::vector< float > > l1Vertices_extra_sumPt_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::unordered_map< std::string, std::vector< unsigned > > l1Vertices_branchMap_numTracks_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool isLooselyGenuine(TTTrackPtrT< T > aTrack) const
std::map< std::string, edm::EDGetTokenT< TTTrackCollectionView > > l1TracksTokenMap_
list status
Definition: mps_update.py:107
std::map< std::string, edm::EDGetTokenT< TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > > > l1TracksMapTokenMap_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::map< std::string, edm::EDGetTokenT< std::vector< l1t::Vertex > > > l1VerticesTokenMap_
assert(be >=bs)
const Vertex & getGenVertex() const
Get primary vertex information (vertex from gen particles)
Definition: InputData.h:66
std::vector< std::vector< float > > l1Vertices_extra_z0_etaWeighted_
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:14
std::map< std::string, RecoTracksBranchData > l1TracksBranchData_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Stores association of Truth Particles (TP) to L1 Track-Trigger Tracks.
int pdgId() const final
PDG identifier.
bool isCombinatoric(TTTrackPtrT< T > aTrack) const
Both isLooselyGenuine() &amp; isUnknown() are false.
RecoVertex< L1TrackTruthMatched > RecoVertexWithTP
Definition: RecoVertex.h:89
tuple genParticlesH
int iEvent
Definition: GenABIO.cc:224
std::vector< float > truePileUpVtxZ0_
Simple wrapper class for TTTrack, with match to a tracking particle.
unsigned int debug() const
Definition: AlgoSettings.h:71
bool isGenuine(TTTrackPtrT< T > aTrack) const
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupSummaryToken_
bool isNull() const
Checks for null.
Definition: Ptr.h:142
bool isAvailable() const
Definition: Service.h:40
const Vertex & getHepMCVertex() const
Get primary vertex information (vertex from HepMCProduct)
Definition: InputData.h:64
tuple handle
Definition: patZpeak.py:23
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const TPPtrToRefMap & getTPPtrToRefMap() const
Get the TrackingParticle to TP translation map.
Definition: InputData.h:62
TTTrackAssociationMap< Ref_Phase2TrackerDigi_ > TTTrackAssMap
std::unordered_map< std::string, std::vector< float > > l1Vertices_branchMap_z0_etaWeighted_
const edm::EDGetTokenT< edm::ValueMap< l1tVertexFinder::TP > > vTPsToken_
edm::View< TTTrack< Ref_Phase2TrackerDigi_ > > TTTrackCollectionView
Log< level::Info, false > LogInfo
std::ostream & operator<<(std::ostream &out, const reco::GenParticle &particle)
std::map< std::string, edm::EDGetTokenT< std::vector< l1t::Vertex > > > l1VerticesExtraTokenMap_
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const TrackingParticlePtr & findTrackingParticlePtr(TTTrackPtrT< T > aTrack) const
GenJetsBranchData genJetsBranchData_
void analyze(const edm::Event &evt, const edm::EventSetup &setup) override
list entry
Definition: mps_splice.py:68
TrueTracksBranchData trueTracksBranchData_
std::map< std::string, RecoVerticesBranchData > l1VerticesBranchData_
const std::vector< Vertex > & getPileUpVertices() const
Get pile-up vertices information.
Definition: InputData.h:70
bool isUnknown(TTTrackPtrT< T > aTrack) const
More than one stub on track is &quot;unknown&quot;.
std::unordered_map< std::string, std::vector< float > > l1Vertices_branchMap_z0_
const edm::EDGetTokenT< std::vector< reco::GenJet > > genJetsToken_
const edm::EDGetTokenT< l1tVertexFinder::InputData > inputDataToken_
std::unordered_map< std::string, std::vector< float > > l1Vertices_branchMap_sumPt_
std::map< std::string, std::string > l1VerticesInputMap_
std::vector< std::vector< unsigned > > trackIdxs
GenParticlesBranchData genParticlesHardOutgoingBranchData_
const edm::EDGetTokenT< std::vector< l1tVertexFinder::TP > > allMatchedTPsToken_