CMS 3D CMS Logo

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