CMS 3D CMS Logo

JetIdSelector.cc
Go to the documentation of this file.
1 
33 
37 
50 
51 #include <memory>
52 #include <vector>
53 #include <sstream>
54 
56 // class definition
58 template <typename T>
60 public:
61  typedef std::vector<T> JetCollection;
62  // construction/destruction
63  explicit JetIdSelector(const edm::ParameterSet& iConfig);
64  ~JetIdSelector() override;
65 
66  // member functions
67  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
68  void endJob() override;
69 
70 private:
71  // member data
76 
77  unsigned int nJetsTot_;
78  unsigned int nJetsPassed_;
83 };
84 
85 using namespace std;
86 
88 // construction/destruction
90 //______________________________________________________________________________
91 template <typename T>
93  : src_(iConfig.getParameter<edm::InputTag>("src")),
94  qualityStr(iConfig.getParameter<string>("idLevel")),
95  jetIDMap_(iConfig.getUntrackedParameter<edm::InputTag>("jetIDMap", edm::InputTag("ak5JetID"))),
96  moduleLabel_(iConfig.getParameter<string>("@module_label")),
97  nJetsTot_(0),
98  nJetsPassed_(0) {
99  produces<JetCollection>();
100 
101  use_pfloose = false;
102  use_pfmedium = false;
103  use_pftight = false;
104 
105  if (qualityStr == "MINIMAL") {
107  use_pfloose = true;
108  } else if (qualityStr == "LOOSE_AOD") {
110  use_pfloose = true;
111  } else if (qualityStr == "LOOSE") {
113  use_pfloose = true;
114  } else if (qualityStr == "MEDIUM") {
116  // There is no medium quality for CaloJet !!
117  use_pfmedium = true;
118  } else if (qualityStr == "TIGHT") {
120  use_pftight = true;
121  } else
122  throw cms::Exception("InvalidInput") << "Expect quality to be one of MINIMAL, LOOSE_AOD, LOOSE, MEDIUM, TIGHT"
123  << std::endl;
124 }
125 
126 //______________________________________________________________________________
127 template <typename T>
129  if (jetIDFunctor)
130  delete jetIDFunctor;
131 }
132 
134 // implementation of member functions
136 
137 //______________________________________________________________________________
138 template <typename T>
140  auto selectedJets = std::make_unique<JetCollection>();
141  edm::Handle<reco::JetView> hjets; // uncorrected jets!
142  iEvent.getByLabel(src_, hjets);
143  auto const& jets = *hjets;
144 
145  // handle to the jet ID variables, filled in the loop
147  unsigned int idx = 0;
148  bool passed = false;
149 
150  for (edm::View<reco::Jet>::const_iterator ibegin = jets.begin(), iend = jets.end(), iJet = ibegin; iJet != iend;
151  ++iJet) {
152  // initialize the boolean flag to false
153  passed = false;
154 
155  //calculate the Calo jetID
156  auto const& jet = *iJet;
157  const std::type_info& type = typeid(jet);
158  if (type == typeid(reco::CaloJet)) {
159  const reco::CaloJet& calojet = static_cast<const reco::CaloJet&>(jet);
160  edm::RefToBase<reco::Jet> jetRef = jets.refAt(idx);
161  if (not hJetIDMap.isValid()) {
162  iEvent.getByLabel(jetIDMap_, hJetIDMap);
163  }
164  reco::JetID const& jetId = (*hJetIDMap)[jetRef];
165  passed = (*jetIDFunctor)(calojet, jetId);
166  }
167 
168  //calculate the PF jetID
169  if (type == typeid(reco::PFJet)) {
170  const reco::PFJet& pfjet = static_cast<const reco::PFJet&>(jet);
171  bool passingLoose = false;
172  bool passingMedium = false;
173  bool passingTight = false;
174  bool ThisIsClean = true;
175  //apply following only if |eta|<2.4: CHF>0, CEMF<0.99, chargedMultiplicity>0
176  if ((pfjet.chargedHadronEnergy() / pfjet.energy()) <= 0.0 && fabs(pfjet.eta()) < 2.4)
177  ThisIsClean = false;
178  if ((pfjet.chargedEmEnergy() / pfjet.energy()) >= 0.99 && fabs(pfjet.eta()) < 2.4)
179  ThisIsClean = false;
180  if (pfjet.chargedMultiplicity() <= 0 && fabs(pfjet.eta()) < 2.4)
181  ThisIsClean = false;
182 
183  // always require #Constituents > 1
184  if (pfjet.nConstituents() <= 1)
185  ThisIsClean = false;
186 
187  if (ThisIsClean && (pfjet.neutralHadronEnergy() / pfjet.energy()) < 0.99 &&
188  (pfjet.neutralEmEnergy() / pfjet.energy()) < 0.99)
189  passingLoose = true;
190 
191  if (ThisIsClean && (pfjet.neutralHadronEnergy() / pfjet.energy()) < 0.95 &&
192  (pfjet.neutralEmEnergy() / pfjet.energy()) < 0.95)
193  passingMedium = true;
194 
195  if (ThisIsClean && (pfjet.neutralHadronEnergy() / pfjet.energy()) < 0.90 &&
196  (pfjet.neutralEmEnergy() / pfjet.energy()) < 0.90)
197  passingTight = true;
198 
199  if (use_pfloose && passingLoose)
200  passed = true;
201  if (use_pfmedium && passingMedium)
202  passed = true;
203  if (use_pftight && passingTight)
204  passed = true;
205  }
206 
207  if (type == typeid(reco::GenJet) || type == typeid(reco::JPTJet)) {
208  edm::LogWarning("JetId") << "Criteria for jets other than CaloJets and PFJets are not yet implemented";
209  passed = true;
210  } // close GenJet, JPT jet
211 
212  const T& goodJet = static_cast<const T&>(jet);
213  if (passed)
214  selectedJets->push_back(goodJet);
215 
216  idx++;
217  } // close jet iterator
218 
219  nJetsTot_ += jets.size();
220  nJetsPassed_ += selectedJets->size();
222 }
223 
224 //______________________________________________________________________________
225 template <typename T>
227  stringstream ss;
228  ss << "nJetsTot=" << nJetsTot_ << " nJetsPassed=" << nJetsPassed_
229  << " fJetsPassed=" << 100. * (nJetsPassed_ / (double)nJetsTot_) << "%\n";
230  cout << "++++++++++++++++++++++++++++++++++++++++++++++++++"
231  << "\n"
232  << moduleLabel_ << "(JetIdSelector) SUMMARY:\n"
233  << ss.str() << "++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
234 }
235 
237 // plugin definition
243 
Jets made from CaloTowers.
Definition: CaloJet.h:27
std::string qualityStr
float neutralHadronEnergy() const
neutralHadronEnergy
Definition: PFJet.h:99
int chargedMultiplicity() const
chargedMultiplicity
Definition: PFJet.h:152
float chargedEmEnergy() const
chargedEmEnergy
Definition: PFJet.h:139
~JetIdSelector() override
JetIDSelectionFunctor * jetIDFunctor
float neutralEmEnergy() const
neutralEmEnergy
Definition: PFJet.h:147
edm::InputTag src_
JetIdSelector< reco::CaloJet > CaloJetIdSelector
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
JetIdSelector(const edm::ParameterSet &iConfig)
Jet ID object.
Definition: JetID.h:16
unsigned int nJetsPassed_
Jets made from PFObjects.
Definition: PFJet.h:20
std::string moduleLabel_
unsigned int nJetsTot_
int iEvent
Definition: GenABIO.cc:224
JetIdSelector< reco::JPTJet > JPTJetIdSelector
virtual int nConstituents() const
of constituents
Definition: Jet.h:65
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:28
Jets made from MC generator particles.
Definition: GenJet.h:23
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Jet selector for pat::Jets and for CaloJets.
JetIdSelector< reco::GenJet > GenJetIdSelector
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
float chargedHadronEnergy() const
chargedHadronEnergy
Definition: PFJet.h:95
std::vector< T > JetCollection
JetIdSelector< reco::PFJet > PFJetIdSelector
void endJob() override
Log< level::Warning, false > LogWarning
long double T
edm::InputTag jetIDMap_
def move(src, dest)
Definition: eostools.py:511
double energy() const final
energy
double eta() const final
momentum pseudorapidity