CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FlavorHistoryEvent.cc
Go to the documentation of this file.
2 #include "TLorentzVector.h"
3 
4 #include <iostream>
5 
6 using namespace reco;
7 using namespace std;
8 
9 // Loop over flavor histories, count number of genjets with
10 // flavor b, c, or l
12 {
13 
14  bool verbose = false;
15 
16  if ( verbose ) cout << "----- Caching Flavor History Event -----" << endl;
17  // Set cached to false
18  cached_ = false;
19  nb_ = nc_ = 0;
20  highestFlavor_ = 0;
21  dR_ = 0.0;
22  flavorSource_ = FlavorHistory::FLAVOR_NULL;
23 
24  // get list of flavor --> type --> dR.
25  // Will sort this later to determine event classification
26  vector<helpers::FlavorHistoryEventHelper> classification;
27 
28  // get iterators to the history vector
29  const_iterator i = histories_.begin(),
30  ibegin = histories_.begin(),
31  iend = histories_.end();
32  // loop over the history vector and count the number of
33  // partons of flavors "b" and "c" that have a matched genjet.
34  for ( ; i != iend; ++i ) {
35  FlavorHistory const & flavHist = *i;
36  if ( verbose ) cout << " Processing flavor history: " << i - ibegin << " = " << endl << flavHist << endl;
37  CandidatePtr const & parton = flavHist.parton();
38  flavor_type flavorSource = flavHist.flavorSource();
39 
40  // Now examine the matched jets to see what the classification should be.
41  int pdgId = -1;
42  if ( parton.isNonnull() ) pdgId = abs(parton->pdgId());
43  ShallowClonePtrCandidate const & matchedJet = flavHist.matchedJet();
44  // Only count events with a matched genjet
45  if ( matchedJet.masterClonePtr().isNonnull() ) {
46  TLorentzVector p41 ( matchedJet.px(), matchedJet.py(), matchedJet.pz(), matchedJet.energy() );
47  if ( pdgId == 5 ) nb_++;
48  if ( pdgId == 4 ) nc_++;
49 
50  // Get the sister genjet
51  ShallowClonePtrCandidate const & sisterJet = i->sisterJet();
52  TLorentzVector p42 ( sisterJet.px(), sisterJet.py(), sisterJet.pz(), sisterJet.energy() );
53 
54 
55  // Now check the source.
56  double dR = -1;
57  if ( sisterJet.masterClonePtr().isNonnull() ) {
58  dR = p41.DeltaR( p42 );
59  }
60  // Add to the vector to be sorted later
61  if ( verbose ) cout << "Adding classification: pdgId = " << pdgId << ", flavorSource = " << flavorSource << ", dR = " << dR << endl;
62  classification.push_back( helpers::FlavorHistoryEventHelper ( pdgId, flavorSource, dR ) );
63  } else{
64  if ( verbose ) cout << "No matched jet found, not adding to classification list" << endl;
65  }
66  }
67 
68 
69  // Sort by priority
70 
71  // Priority is:
72  //
73  // 1. flavor (5 > 4)
74  // 2. type:
75  // 2a. Flavor decay
76  // 2b. Matrix element
77  // 2c. Flavor excitation
78  // 2d. Gluon splitting
79  // 3. delta R (if applicable)
80  if ( classification.size() > 0 ) {
81 
82 
83  std::sort( classification.begin(), classification.end() );
84 
85  if ( verbose ){ cout << "Writing out list of classifications" << endl;
86  copy(classification.begin(), classification.end(),
87  ostream_iterator<helpers::FlavorHistoryEventHelper>(cout, ""));
88  }
89 
90  helpers::FlavorHistoryEventHelper const & best = *(classification.rbegin());
91  dR_ = best.dR;
92  highestFlavor_ = best.flavor;
93  flavorSource_ = best.flavorSource;
94  }
95  else {
96  dR_ = -1.0;
97  highestFlavor_ = 0;
98  flavorSource_ = FlavorHistory::FLAVOR_NULL;
99  }
100 
101  // now we're cached, can return values quickly
102  cached_ = true;
103 }
104 
105 
106 
int i
Definition: DBlmapReader.cc:9
virtual double energy() const final
energy
virtual const CandidatePtr & masterClonePtr() const
returns reference to master clone pointer
const reco::ShallowClonePtrCandidate & matchedJet() const
Definition: FlavorHistory.h:99
FLAVOR_T flavorSource() const
Definition: FlavorHistory.h:89
collection_type::const_iterator const_iterator
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual double py() const final
y coordinate of momentum vector
virtual double pz() const final
z coordinate of momentum vector
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:169
virtual double px() const final
x coordinate of momentum vector
tuple cout
Definition: gather_cfg.py:145
const reco::CandidatePtr & parton() const
Definition: FlavorHistory.h:95