CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Tau.cc
Go to the documentation of this file.
1 //
2 //
3 
6 #include <algorithm>
7 #include <boost/bind.hpp>
8 
9 using namespace pat;
10 
11 
13 Tau::Tau() :
14  Lepton<reco::BaseTau>()
15  ,embeddedIsolationTracks_(false)
16  ,embeddedLeadTrack_(false)
17  ,embeddedSignalTracks_(false)
18  ,embeddedLeadPFCand_(false)
19  ,embeddedLeadPFChargedHadrCand_(false)
20  ,embeddedLeadPFNeutralCand_(false)
21  ,embeddedSignalPFCands_(false)
22  ,embeddedSignalPFChargedHadrCands_(false)
23  ,embeddedSignalPFNeutralHadrCands_(false)
24  ,embeddedSignalPFGammaCands_(false)
25  ,embeddedIsolationPFCands_(false)
26  ,embeddedIsolationPFChargedHadrCands_(false)
27  ,embeddedIsolationPFNeutralHadrCands_(false)
28  ,embeddedIsolationPFGammaCands_(false)
29 {
30 }
31 
33 Tau::Tau(const reco::BaseTau & aTau) :
34  Lepton<reco::BaseTau>(aTau)
35  ,embeddedIsolationTracks_(false)
36  ,embeddedLeadTrack_(false)
37  ,embeddedSignalTracks_(false)
38  ,embeddedLeadPFCand_(false)
39  ,embeddedLeadPFChargedHadrCand_(false)
40  ,embeddedLeadPFNeutralCand_(false)
41  ,embeddedSignalPFCands_(false)
42  ,embeddedSignalPFChargedHadrCands_(false)
43  ,embeddedSignalPFNeutralHadrCands_(false)
44  ,embeddedSignalPFGammaCands_(false)
45  ,embeddedIsolationPFCands_(false)
46  ,embeddedIsolationPFChargedHadrCands_(false)
47  ,embeddedIsolationPFNeutralHadrCands_(false)
48  ,embeddedIsolationPFGammaCands_(false)
49 {
50  const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(&aTau);
51  if (pfTau != 0){
52  pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
53  pfEssential_.push_back(pat::tau::TauPFEssential(*pfTau));
54  }
55  const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(&aTau);
56  if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
57 }
58 
60 Tau::Tau(const edm::RefToBase<reco::BaseTau> & aTauRef) :
61  Lepton<reco::BaseTau>(aTauRef)
62  ,embeddedIsolationTracks_(false)
63  ,embeddedLeadTrack_(false)
64  ,embeddedSignalTracks_(false)
65  ,embeddedLeadPFCand_(false)
66  ,embeddedLeadPFChargedHadrCand_(false)
67  ,embeddedLeadPFNeutralCand_(false)
68  ,embeddedSignalPFCands_(false)
69  ,embeddedSignalPFChargedHadrCands_(false)
70  ,embeddedSignalPFNeutralHadrCands_(false)
71  ,embeddedSignalPFGammaCands_(false)
72  ,embeddedIsolationPFCands_(false)
73  ,embeddedIsolationPFChargedHadrCands_(false)
74  ,embeddedIsolationPFNeutralHadrCands_(false)
75  ,embeddedIsolationPFGammaCands_(false)
76 {
77  const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(aTauRef.get());
78  if (pfTau != 0){
79  pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
80  pfEssential_.push_back(pat::tau::TauPFEssential(*pfTau));
81  }
82  const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(aTauRef.get());
83  if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
84 }
85 
87 Tau::Tau(const edm::Ptr<reco::BaseTau> & aTauRef) :
88  Lepton<reco::BaseTau>(aTauRef)
89  ,embeddedIsolationTracks_(false)
90  ,embeddedLeadTrack_(false)
91  ,embeddedSignalTracks_(false)
92  ,embeddedLeadPFCand_(false)
93  ,embeddedLeadPFChargedHadrCand_(false)
94  ,embeddedLeadPFNeutralCand_(false)
95  ,embeddedSignalPFCands_(false)
96  ,embeddedSignalPFChargedHadrCands_(false)
97  ,embeddedSignalPFNeutralHadrCands_(false)
98  ,embeddedSignalPFGammaCands_(false)
99  ,embeddedIsolationPFCands_(false)
100  ,embeddedIsolationPFChargedHadrCands_(false)
101  ,embeddedIsolationPFNeutralHadrCands_(false)
102  ,embeddedIsolationPFGammaCands_(false)
103 {
104  const reco::PFTau * pfTau = dynamic_cast<const reco::PFTau *>(aTauRef.get());
105  if (pfTau != 0){
106  pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau));
107  pfEssential_.push_back(pat::tau::TauPFEssential(*pfTau));
108  }
109  const reco::CaloTau * caloTau = dynamic_cast<const reco::CaloTau *>(aTauRef.get());
110  if (caloTau != 0) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau));
111 }
112 
114 Tau::~Tau() {
115 }
116 
117 std::ostream&
118 reco::operator<<(std::ostream& out, const pat::Tau& obj)
119 {
120  if(!out) return out;
121 
122  out << "\tpat::Tau: ";
123  out << std::setiosflags(std::ios::right);
124  out << std::setiosflags(std::ios::fixed);
125  out << std::setprecision(3);
126  out << " E/pT/eta/phi "
127  << obj.energy()<<"/"
128  << obj.pt()<<"/"
129  << obj.eta()<<"/"
130  << obj.phi();
131  return out;
132 }
133 
135 const reco::TrackRefVector & Tau::isolationTracks() const {
136  if (embeddedIsolationTracks_) {
137  if (!isolationTracksTransientRefVector_.isSet()) {
138  std::unique_ptr<reco::TrackRefVector> trackRefVec{ new reco::TrackRefVector{}};
139  trackRefVec->reserve(isolationTracks_.size());
140  for (unsigned int i = 0; i < isolationTracks_.size(); i++) {
141  trackRefVec->push_back(reco::TrackRef(&isolationTracks_, i));
142  }
143  isolationTracksTransientRefVector_.set(std::move(trackRefVec));
144  }
145  return *isolationTracksTransientRefVector_;
146  } else {
148  }
149 }
150 
151 
154  if (embeddedLeadTrack_) {
155  return reco::TrackRef(&leadTrack_, 0);
156  } else {
157  return reco::BaseTau::leadTrack();
158  }
159 }
160 
161 
163 const reco::TrackRefVector & Tau::signalTracks() const {
164  if (embeddedSignalTracks_) {
165  if (!signalTracksTransientRefVector_.isSet()) {
166  std::unique_ptr<reco::TrackRefVector> trackRefVec{ new reco::TrackRefVector{} };
167  trackRefVec->reserve(signalTracks_.size());
168  for (unsigned int i = 0; i < signalTracks_.size(); i++) {
169  trackRefVec->push_back(reco::TrackRef(&signalTracks_, i));
170  }
171  signalTracksTransientRefVector_.set(std::move(trackRefVec));
172  }
173  return *signalTracksTransientRefVector_;
174  } else {
176  }
177 }
178 
179 
181 void Tau::embedIsolationTracks() {
182  isolationTracks_.clear();
184  for (unsigned int i = 0; i < trackRefVec.size(); i++) {
185  isolationTracks_.push_back(*trackRefVec.at(i));
186  }
187  embeddedIsolationTracks_ = true;
188 }
189 
190 
192 void Tau::embedLeadTrack() {
193  leadTrack_.clear();
194  if (reco::BaseTau::leadTrack().isNonnull()) {
195  leadTrack_.push_back(*reco::BaseTau::leadTrack());
196  embeddedLeadTrack_ = true;
197  }
198 }
199 
200 
202 void Tau::embedSignalTracks(){
203  signalTracks_.clear();
205  for (unsigned int i = 0; i < trackRefVec.size(); i++) {
206  signalTracks_.push_back(*trackRefVec.at(i));
207  }
208  embeddedSignalTracks_ = true;
209 }
210 
211 
213 void Tau::setGenJet(const reco::GenJetRef& gj) {
214  genJet_.clear();
215  genJet_.push_back(*gj);
216 }
217 
219 const reco::GenJet * Tau::genJet() const {
220  return (genJet_.size() > 0 ? &genJet_.front() : 0);
221 }
222 
223 
224 // method to retrieve a tau ID (or throw)
225 float Tau::tauID(const std::string & name) const {
226  for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
227  if (it->first == name) return it->second;
228  }
229  cms::Exception ex("Key not found");
230  ex << "pat::Tau: the ID " << name << " can't be found in this pat::Tau.\n";
231  ex << "The available IDs are: ";
232  for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
233  ex << "'" << it->first << "' ";
234  }
235  ex << ".\n";
236  throw ex;
237 }
238 // check if an ID is there
239 bool Tau::isTauIDAvailable(const std::string & name) const {
240  for (std::vector<IdPair>::const_iterator it = tauIDs_.begin(), ed = tauIDs_.end(); it != ed; ++it) {
241  if (it->first == name) return true;
242  }
243  return false;
244 }
245 
246 
247 const pat::tau::TauPFSpecific & Tau::pfSpecific() const {
248  if (!isPFTau()) throw cms::Exception("Type Error") << "Requesting a PFTau-specific information from a pat::Tau which wasn't made from a PFTau.\n";
249  return pfSpecific_[0];
250 }
251 
252 const pat::tau::TauPFEssential & Tau::pfEssential() const {
253  if (pfEssential_.empty()) throw cms::Exception("Type Error") << "Requesting a PFTau-specific information from a pat::Tau which wasn't made from a PFTau.\n";
254  return pfEssential_[0];
255 }
256 
257 
258 const pat::tau::TauCaloSpecific & Tau::caloSpecific() const {
259  if (!isCaloTau()) throw cms::Exception("Type Error") << "Requesting a CaloTau-specific information from a pat::Tau which wasn't made from a CaloTau.\n";
260  return caloSpecific_[0];
261 }
262 
263 reco::Candidate::LorentzVector Tau::p4Jet() const
264 {
265  if ( isCaloTau() ) return caloSpecific().p4Jet_;
266  if ( isPFTau() ) return reco::Candidate::LorentzVector(pfEssential().p4Jet_);
267  throw cms::Exception("Type Error") << "Requesting a CaloTau/PFTau-specific information from a pat::Tau which wasn't made from either a CaloTau or a PFTau.\n";
268 }
269 
270 float Tau::dxy_Sig() const
271 {
272  if ( pfEssential().dxy_error_ != 0 ) return (pfEssential().dxy_/pfEssential().dxy_error_);
273  else return 0.;
274 }
275 
276 pat::tau::TauPFEssential::CovMatrix Tau::flightLengthCov() const
277 {
279  const pat::tau::TauPFEssential::CovMatrix& sv = secondaryVertexCov();
280  const pat::tau::TauPFEssential::CovMatrix& pv = primaryVertexCov();
281  for ( int i = 0; i < dimension; ++i ) {
282  for ( int j = 0; j < dimension; ++j ) {
283  cov(i,j) = sv(i,j) + pv(i,j);
284  }
285  }
286  return cov;
287 }
288 
289 float Tau::etaetaMoment() const
290 {
291  if ( isCaloTau() ) return caloSpecific().etaetaMoment_;
292  if ( isPFTau() ) return pfSpecific().etaetaMoment_;
293  throw cms::Exception("Type Error") << "Requesting a CaloTau/PFTau-specific information from a pat::Tau which wasn't made from either a CaloTau or a PFTau.\n";
294 }
295 
296 float Tau::phiphiMoment() const
297 {
298  if ( isCaloTau() ) return caloSpecific().phiphiMoment_;
299  if ( isPFTau() ) return pfSpecific().phiphiMoment_;
300  throw cms::Exception("Type Error") << "Requesting a CaloTau/PFTau-specific information from a pat::Tau which wasn't made from either a CaloTau or a PFTau.\n";
301 }
302 
303 float Tau::etaphiMoment() const
304 {
305  if ( isCaloTau() ) return caloSpecific().etaphiMoment_;
306  if ( isPFTau() ) return pfSpecific().etaphiMoment_;
307  throw cms::Exception("Type Error") << "Requesting a CaloTau/PFTau-specific information from a pat::Tau which wasn't made from either a CaloTau or a PFTau.\n";
308 }
309 
310 void Tau::setDecayMode(int decayMode)
311 {
312  if (!isPFTau()) throw cms::Exception("Type Error") << "Requesting a PFTau-specific information from a pat::Tau which wasn't made from a PFTau.\n";
313  pfEssential_[0].decayMode_ = decayMode;
314 }
315 
317 void Tau::embedLeadPFCand() {
318  if (!isPFTau() ) {//additional check with warning in pat::tau producer
319  return;
320  }
321  leadPFCand_.clear();
322  if (pfSpecific_[0].leadPFCand_.isNonnull() ) {
323  leadPFCand_.push_back(*pfSpecific_[0].leadPFCand_); //already set in C-tor
324  embeddedLeadPFCand_ = true;
325  }
326 }
328 void Tau::embedLeadPFChargedHadrCand() {
329  if (!isPFTau() ) {//additional check with warning in pat::tau producer
330  return;
331  }
332  leadPFChargedHadrCand_.clear();
333  if (pfSpecific_[0].leadPFChargedHadrCand_.isNonnull() ) {
334  leadPFChargedHadrCand_.push_back(*pfSpecific_[0].leadPFChargedHadrCand_); //already set in C-tor
335  embeddedLeadPFChargedHadrCand_ = true;
336  }
337 }
339 void Tau::embedLeadPFNeutralCand() {
340  if (!isPFTau() ) {//additional check with warning in pat::tau producer
341  return;
342  }
343  leadPFNeutralCand_.clear();
344  if (pfSpecific_[0].leadPFNeutralCand_.isNonnull() ) {
345  leadPFNeutralCand_.push_back(*pfSpecific_[0].leadPFNeutralCand_); //already set in C-tor
346  embeddedLeadPFNeutralCand_ = true;
347  }
348 }
349 
350 void Tau::embedSignalPFCands() {
351  if (!isPFTau() ) {//additional check with warning in pat::tau producer
352  return;
353  }
354  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedSignalPFCands_;
355  for (unsigned int i = 0; i < candPtrs.size(); i++) {
356  signalPFCands_.push_back(*candPtrs.at(i));
357  }
358  embeddedSignalPFCands_ = true;
359 }
360 void Tau::embedSignalPFChargedHadrCands() {
361  if (!isPFTau() ) {//additional check with warning in pat::tau producer
362  return;
363  }
364  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedSignalPFChargedHadrCands_;
365  for (unsigned int i = 0; i < candPtrs.size(); i++) {
366  signalPFChargedHadrCands_.push_back(*candPtrs.at(i));
367  }
368  embeddedSignalPFChargedHadrCands_ = true;
369 }
370 void Tau::embedSignalPFNeutralHadrCands() {
371  if (!isPFTau() ) {//additional check with warning in pat::tau producer
372  return;
373  }
374  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedSignalPFNeutrHadrCands_;
375  for (unsigned int i = 0; i < candPtrs.size(); i++) {
376  signalPFNeutralHadrCands_.push_back(*candPtrs.at(i));
377  }
378  embeddedSignalPFNeutralHadrCands_ = true;
379 }
380 void Tau::embedSignalPFGammaCands() {
381  if (!isPFTau() ) {//additional check with warning in pat::tau producer
382  return;
383  }
384  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedSignalPFGammaCands_;
385  for (unsigned int i = 0; i < candPtrs.size(); i++) {
386  signalPFGammaCands_.push_back(*candPtrs.at(i));
387  }
388  embeddedSignalPFGammaCands_ = true;
389 }
390 
391 void Tau::embedIsolationPFCands() {
392  if (!isPFTau() ) {//additional check with warning in pat::tau producer
393  return;
394  }
395  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedIsolationPFCands_;
396  for (unsigned int i = 0; i < candPtrs.size(); i++) {
397  isolationPFCands_.push_back(*candPtrs.at(i));
398  }
399  embeddedIsolationPFCands_ = true;
400 }
401 
402 void Tau::embedIsolationPFChargedHadrCands() {
403  if (!isPFTau() ) {//additional check with warning in pat::tau producer
404  return;
405  }
406  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedIsolationPFChargedHadrCands_;
407  for (unsigned int i = 0; i < candPtrs.size(); i++) {
408  isolationPFChargedHadrCands_.push_back(*candPtrs.at(i));
409  }
410  embeddedIsolationPFChargedHadrCands_ = true;
411 }
412 void Tau::embedIsolationPFNeutralHadrCands() {
413  if (!isPFTau() ) {//additional check with warning in pat::tau producer
414  return;
415  }
416  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedIsolationPFNeutrHadrCands_;
417  for (unsigned int i = 0; i < candPtrs.size(); i++) {
418  isolationPFNeutralHadrCands_.push_back(*candPtrs.at(i));
419  }
420  embeddedIsolationPFNeutralHadrCands_ = true;
421 }
422 void Tau::embedIsolationPFGammaCands() {
423  if (!isPFTau() ) {//additional check with warning in pat::tau producer
424  return;
425  }
426  std::vector<reco::PFCandidatePtr> candPtrs = pfSpecific_[0].selectedIsolationPFGammaCands_;
427  for (unsigned int i = 0; i < candPtrs.size(); i++) {
428  isolationPFGammaCands_.push_back(*candPtrs.at(i));
429  }
430  embeddedIsolationPFGammaCands_ = true;
431 }
432 
433 reco::PFRecoTauChargedHadronRef Tau::leadTauChargedHadronCandidate() const {
434  if(!isPFTau() ) throw cms::Exception("Type Error") << "Requesting content that is not stored in miniAOD.\n";
435  if ( pfSpecific().signalTauChargedHadronCandidates_.size() > 0 ) {
436  return reco::PFRecoTauChargedHadronRef(&pfSpecific().signalTauChargedHadronCandidates_,0);
437  } else {
439  }
440 }
441 
442 const reco::PFCandidatePtr Tau::leadPFChargedHadrCand() const {
443  if(!embeddedLeadPFChargedHadrCand_){
444  if(pfSpecific_.empty()) return reco::PFCandidatePtr();
445  else return pfSpecific().leadPFChargedHadrCand_;
446  }else
447  return reco::PFCandidatePtr(&leadPFChargedHadrCand_,0);
448 }
449 
450 const reco::PFCandidatePtr Tau::leadPFNeutralCand() const {
451  if(!embeddedLeadPFNeutralCand_){
452  if(pfSpecific_.empty()) return reco::PFCandidatePtr();
453  else return pfSpecific().leadPFNeutralCand_;
454  }else
455  return reco::PFCandidatePtr(&leadPFNeutralCand_,0);
456 }
457 
458 const reco::PFCandidatePtr Tau::leadPFCand() const {
459  if(!embeddedLeadPFCand_){
460  if(pfSpecific_.empty()) return reco::PFCandidatePtr();
461  return pfSpecific().leadPFCand_;
462  }else
463  return reco::PFCandidatePtr(&leadPFCand_,0);
464 }
465 
466 const std::vector<reco::PFCandidatePtr>& Tau::signalPFCands() const {
467  if (embeddedSignalPFCands_) {
468  if (!signalPFCandsTransientPtrs_.isSet()) {
469  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
470  aPtrs->reserve(signalPFCands_.size());
471  for (unsigned int i = 0; i < signalPFCands_.size(); i++) {
472  aPtrs->push_back(reco::PFCandidatePtr(&signalPFCands_, i) );
473  }
474  signalPFCandsTransientPtrs_.set(std::move(aPtrs));
475  }
476  return *signalPFCandsTransientPtrs_;
477  } else {
478  if(pfSpecific_.empty() || pfSpecific().selectedSignalPFCands_.empty() || !pfSpecific().selectedSignalPFCands_.front().isAvailable()){
479  // this part of code is called when reading from patTuple or miniAOD
480  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
481  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
482  signalPFCandsTransientPtrs_.set(std::move(aPtrs));
483  return *signalPFCandsTransientPtrs_;
484  } else return pfSpecific().selectedSignalPFCands_;
485  }
486 }
487 
488 const std::vector<reco::PFCandidatePtr>& Tau::signalPFChargedHadrCands() const {
489  if (embeddedSignalPFChargedHadrCands_) {
490  if (!signalPFChargedHadrCandsTransientPtrs_.isSet()) {
491  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{ new std::vector<reco::PFCandidatePtr>{}};
492  aPtrs->reserve(signalPFChargedHadrCands_.size());
493  for (unsigned int i = 0; i < signalPFChargedHadrCands_.size(); i++) {
494  aPtrs->push_back(reco::PFCandidatePtr(&signalPFChargedHadrCands_, i) );
495  }
496  signalPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs));
497  }
498  return *signalPFChargedHadrCandsTransientPtrs_;
499  } else {
500  if(pfSpecific_.empty() || pfSpecific().selectedSignalPFChargedHadrCands_.empty() || !pfSpecific().selectedSignalPFChargedHadrCands_.front().isAvailable()){
501  // this part of code is called when reading from patTuple or miniAOD
502  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
503  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
504  signalPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs));
505  return *signalPFChargedHadrCandsTransientPtrs_;
506  } else return pfSpecific().selectedSignalPFChargedHadrCands_;
507  }
508 }
509 
510 const std::vector<reco::PFCandidatePtr>& Tau::signalPFNeutrHadrCands() const {
511  if (embeddedSignalPFNeutralHadrCands_) {
512  if (!signalPFNeutralHadrCandsTransientPtrs_.isSet()) {
513  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
514  aPtrs->reserve(signalPFNeutralHadrCands_.size());
515  for (unsigned int i = 0; i < signalPFNeutralHadrCands_.size(); i++) {
516  aPtrs->push_back(reco::PFCandidatePtr(&signalPFNeutralHadrCands_, i) );
517  }
518  signalPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs));
519  }
520  return *signalPFNeutralHadrCandsTransientPtrs_;
521  } else {
522  if(pfSpecific_.empty() || pfSpecific().selectedSignalPFNeutrHadrCands_.empty() || !pfSpecific().selectedSignalPFNeutrHadrCands_.front().isAvailable()){
523  // this part of code is called when reading from patTuple or miniAOD
524  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
525  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
526  signalPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs));
527  return *signalPFNeutralHadrCandsTransientPtrs_;
528  } else return pfSpecific().selectedSignalPFNeutrHadrCands_;
529  }
530 }
531 
532 const std::vector<reco::PFCandidatePtr>& Tau::signalPFGammaCands() const {
533  if (embeddedSignalPFGammaCands_) {
534  if (!signalPFGammaCandsTransientPtrs_.isSet()) {
535  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{ new std::vector<reco::PFCandidatePtr>{}};
536  aPtrs->reserve(signalPFGammaCands_.size());
537  for (unsigned int i = 0; i < signalPFGammaCands_.size(); i++) {
538  aPtrs->push_back(reco::PFCandidatePtr(&signalPFGammaCands_, i) );
539  }
540  signalPFGammaCandsTransientPtrs_.set(std::move(aPtrs));
541  }
542  return *signalPFGammaCandsTransientPtrs_;
543  } else {
544  if(pfSpecific_.empty() || pfSpecific().selectedSignalPFGammaCands_.empty() || !pfSpecific().selectedSignalPFGammaCands_.front().isAvailable()){
545  // this part of code is called when reading from patTuple or miniAOD
546  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
547  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
548  signalPFGammaCandsTransientPtrs_.set(std::move(aPtrs));
549  return *signalPFGammaCandsTransientPtrs_;
550  } else return pfSpecific().selectedSignalPFGammaCands_;
551  }
552 }
553 
554 const std::vector<reco::PFRecoTauChargedHadron> & Tau::signalTauChargedHadronCandidates() const {
555  if(pfSpecific_.empty()) throw cms::Exception("Type Error") << "Requesting content that is not stored in miniAOD.\n";
556  return pfSpecific().signalTauChargedHadronCandidates_;
557 }
558 
559 const std::vector<reco::RecoTauPiZero> & Tau::signalPiZeroCandidates() const {
560  if(pfSpecific_.empty()) throw cms::Exception("Type Error") << "Requesting content that is not stored in miniAOD.\n";
561  return pfSpecific().signalPiZeroCandidates_;
562 }
563 
564 const std::vector<reco::PFCandidatePtr>& Tau::isolationPFCands() const {
565  if (embeddedIsolationPFCands_) {
566  if (!isolationPFCandsTransientPtrs_.isSet()) {
567  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{ new std::vector<reco::PFCandidatePtr>{}};
568  aPtrs->reserve(isolationPFCands_.size());
569  for (unsigned int i = 0; i < isolationPFCands_.size(); i++) {
570  aPtrs->push_back(reco::PFCandidatePtr(&isolationPFCands_, i) );
571  }
572  isolationPFCandsTransientPtrs_.set(std::move(aPtrs));
573  }
574  return *isolationPFCandsTransientPtrs_;
575  } else {
576  if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFCands_.empty() || !pfSpecific().selectedIsolationPFCands_.front().isAvailable()){
577  // this part of code is called when reading from patTuple or miniAOD
578  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
579  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
580  isolationPFCandsTransientPtrs_.set(std::move(aPtrs));
581  return *isolationPFCandsTransientPtrs_;
582  } else return pfSpecific().selectedIsolationPFCands_;
583  }
584 }
585 
586 const std::vector<reco::PFCandidatePtr>& Tau::isolationPFChargedHadrCands() const {
587  if (embeddedIsolationPFChargedHadrCands_) {
588  if (!isolationPFChargedHadrCandsTransientPtrs_.isSet()) {
589  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{ new std::vector<reco::PFCandidatePtr>{}};
590  aPtrs->reserve(isolationPFChargedHadrCands_.size());
591  for (unsigned int i = 0; i < isolationPFChargedHadrCands_.size(); i++) {
592  aPtrs->push_back(reco::PFCandidatePtr(&isolationPFChargedHadrCands_, i) );
593  }
594  isolationPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs));
595  }
596  return *isolationPFChargedHadrCandsTransientPtrs_;
597  } else {
598  if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFChargedHadrCands_.empty() || !pfSpecific().selectedIsolationPFChargedHadrCands_.front().isAvailable()){
599  // this part of code is called when reading from patTuple or miniAOD
600  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
601  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
602  isolationPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs));
603  return *isolationPFChargedHadrCandsTransientPtrs_;
604  } else return pfSpecific().selectedIsolationPFChargedHadrCands_;
605  }
606 }
607 
608 const std::vector<reco::PFCandidatePtr>& Tau::isolationPFNeutrHadrCands() const {
609  if (embeddedIsolationPFNeutralHadrCands_) {
610  if (!isolationPFNeutralHadrCandsTransientPtrs_.isSet()) {
611  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{ new std::vector<reco::PFCandidatePtr>{}};
612  aPtrs->reserve(isolationPFNeutralHadrCands_.size());
613  for (unsigned int i = 0; i < isolationPFNeutralHadrCands_.size(); i++) {
614  aPtrs->push_back(reco::PFCandidatePtr(&isolationPFNeutralHadrCands_, i) );
615  }
616  isolationPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs));
617  }
618  return *isolationPFNeutralHadrCandsTransientPtrs_;
619  } else {
620  if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFNeutrHadrCands_.empty() || !pfSpecific().selectedIsolationPFNeutrHadrCands_.front().isAvailable()){
621  // this part of code is called when reading from patTuple or miniAOD
622  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
623  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
624  isolationPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs));
625  return *isolationPFNeutralHadrCandsTransientPtrs_;
626  } else return pfSpecific().selectedIsolationPFNeutrHadrCands_;
627  }
628 }
629 
630 const std::vector<reco::PFCandidatePtr>& Tau::isolationPFGammaCands() const {
631  if (embeddedIsolationPFGammaCands_) {
632  if (!isolationPFGammaCandsTransientPtrs_.isSet()) {
633  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
634  aPtrs->reserve(isolationPFGammaCands_.size());
635  for (unsigned int i = 0; i < isolationPFGammaCands_.size(); i++) {
636  aPtrs->push_back(reco::PFCandidatePtr(&isolationPFGammaCands_, i) );
637  }
638  isolationPFGammaCandsTransientPtrs_.set(std::move(aPtrs));
639  }
640  return *isolationPFGammaCandsTransientPtrs_;
641  } else {
642  if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFGammaCands_.empty() || !pfSpecific().selectedIsolationPFGammaCands_.front().isAvailable()){
643  // this part of code is called when reading from patTuple or miniAOD
644  // it returns empty collection in correct format so it can be substituted by reco::Candidates if available
645  std::unique_ptr<std::vector<reco::PFCandidatePtr> > aPtrs{new std::vector<reco::PFCandidatePtr>{}};
646  isolationPFGammaCandsTransientPtrs_.set(std::move(aPtrs));
647  return *isolationPFGammaCandsTransientPtrs_;
648  } else return pfSpecific().selectedIsolationPFGammaCands_;
649  }
650 }
651 
652 const std::vector<reco::PFRecoTauChargedHadron> & Tau::isolationTauChargedHadronCandidates() const {
653  if(pfSpecific_.empty()) throw cms::Exception("Type Error") << "Requesting content that is not stored in miniAOD.\n";
654  return pfSpecific().isolationTauChargedHadronCandidates_;
655 }
656 
657 const std::vector<reco::RecoTauPiZero> & Tau::isolationPiZeroCandidates() const {
658  if(pfSpecific_.empty()) throw cms::Exception("Type Error") << "Requesting content that is not stored in miniAOD.\n";
659  return pfSpecific().isolationPiZeroCandidates_;
660 }
661 
664 
665 // initialize the jet to a given JEC level during creation starting from Uncorrected
666 void Tau::initializeJEC(unsigned int level, unsigned int set)
667 {
668  currentJECSet(set);
669  currentJECLevel(level);
670  setP4(jec_[set].correction(level)*p4());
671 }
672 
674 int Tau::jecSet(const std::string& set) const
675 {
676  for ( std::vector<pat::TauJetCorrFactors>::const_iterator corrFactor = jec_.begin();
677  corrFactor != jec_.end(); ++corrFactor ) {
678  if ( corrFactor->jecSet() == set ) return corrFactor-jec_.begin();
679  }
680  return -1;
681 }
682 
684 const std::vector<std::string> Tau::availableJECSets() const
685 {
686  std::vector<std::string> sets;
687  for ( std::vector<pat::TauJetCorrFactors>::const_iterator corrFactor = jec_.begin();
688  corrFactor != jec_.end(); ++corrFactor ) {
689  sets.push_back(corrFactor->jecSet());
690  }
691  return sets;
692 }
693 
694 const std::vector<std::string> Tau::availableJECLevels(const int& set) const
695 {
696  return set>=0 ? jec_.at(set).correctionLabels() : std::vector<std::string>();
697 }
698 
701 float Tau::jecFactor(const std::string& level, const std::string& set) const
702 {
703  for ( unsigned int idx = 0; idx < jec_.size(); ++idx ) {
704  if ( set.empty() || jec_.at(idx).jecSet() == set ){
705  if ( jec_[idx].jecLevel(level) >= 0 )
706  return jecFactor(jec_[idx].jecLevel(level), idx);
707  else
708  throw cms::Exception("InvalidRequest")
709  << "This JEC level " << level << " does not exist. \n";
710  }
711  }
712  throw cms::Exception("InvalidRequest")
713  << "This jet does not carry any jet energy correction factor information \n"
714  << "for a jet energy correction set with label " << set << "\n";
715 }
716 
719 float Tau::jecFactor(const unsigned int& level, const unsigned int& set) const
720 {
721  if ( !jecSetsAvailable() )
722  throw cms::Exception("InvalidRequest")
723  << "This jet does not carry any jet energy correction factor information \n";
724  if ( !jecSetAvailable(set) )
725  throw cms::Exception("InvalidRequest")
726  << "This jet does not carry any jet energy correction factor information \n"
727  << "for a jet energy correction set with index " << set << "\n";
728  return jec_.at(set).correction(level)/jec_.at(currentJECSet_).correction(currentJECLevel_);
729 }
730 
733 Tau Tau::correctedTauJet(const std::string& level, const std::string& set) const
734 {
735  // rescale p4 of the jet; the update of current values is
736  // done within the called jecFactor function
737  for ( unsigned int idx = 0; idx < jec_.size(); ++idx ) {
738  if ( set.empty() || jec_.at(idx).jecSet() == set ) {
739  if ( jec_[idx].jecLevel(level) >= 0 )
740  return correctedTauJet(jec_[idx].jecLevel(level), idx);
741  else
742  throw cms::Exception("InvalidRequest")
743  << "This JEC level " << level << " does not exist. \n";
744  }
745  }
746  throw cms::Exception("InvalidRequest")
747  << "This JEC set " << set << " does not exist. \n";
748 }
749 
752 Tau Tau::correctedTauJet(const unsigned int& level, const unsigned int& set) const
753 {
754  Tau correctedTauJet(*this);
755  //rescale p4 of the jet
756  correctedTauJet.setP4(jecFactor(level, set)*p4());
757  // update current level and set
758  correctedTauJet.currentJECSet(set);
759  correctedTauJet.currentJECLevel(level);
760  return correctedTauJet;
761 }
762 
763 
764 
767 // return the leading candidate from signal(PF)ChargedHadrCandPtrs_ collection
768 const reco::CandidatePtr Tau::leadChargedHadrCand() const {
769  const reco::PFCandidatePtr leadPF = leadPFChargedHadrCand();
770  if (leadPF.isAvailable() || signalChargedHadrCandPtrs_.isNull()) return leadPF;
772  for (const reco::CandidatePtr & p : signalChargedHadrCandPtrs_) {
773  if (ret.isNull() || (p->pt() > ret->pt())) ret = p;
774  }
775  return ret;
776 
777 }
778 
780 const reco::CandidatePtr Tau::leadNeutralCand() const {
781  const reco::PFCandidatePtr leadPF = leadPFNeutralCand();
782  if (leadPF.isAvailable() || signalNeutralHadrCandPtrs_.isNull()) return leadPF;
784  for (const reco::CandidatePtr & p : signalNeutralHadrCandPtrs_) {
785  if (ret.isNull() || (p->pt() > ret->pt())) ret = p;
786  }
787  return ret;
788 
789 }
790 
792 const reco::CandidatePtr Tau::leadCand() const {
793  const reco::PFCandidatePtr leadPF = leadPFCand();
794  if (leadPF.isAvailable() || !Tau::ExistSignalCands()) return leadPF;
795  else return Tau::signalCands()[0];
796 }
797 
799 
800 bool Tau::ExistSignalCands() const {
801  return !(signalChargedHadrCandPtrs_.isNull() && signalNeutralHadrCandPtrs_.isNull() && signalGammaCandPtrs_.isNull());
802 }
803 
804 bool Tau::ExistIsolationCands() const {
805  return !(isolationChargedHadrCandPtrs_.isNull() && isolationNeutralHadrCandPtrs_.isNull() && isolationGammaCandPtrs_.isNull());
806 }
807 
810 
811 reco::CandidatePtrVector Tau::signalCands() const {
812  std::vector<reco::PFCandidatePtr> r0 = signalPFCands();
814  if(!Tau::ExistSignalCands() || (!r0.empty() && r0.front().isAvailable())) {
815  for (const auto & p : r0) ret.push_back(p);
816  return ret;
817  } else {
820  std::vector<std::pair<float,size_t> > pt_index;
821  size_t index=0;
822  for (const auto & p : signalChargedHadrCandPtrs_){ ret2.push_back(p); pt_index.push_back(std::make_pair(p->pt(),index)); index++;}
823  for (const auto & p : signalNeutralHadrCandPtrs_){ ret2.push_back(p); pt_index.push_back(std::make_pair(p->pt(),index)); index++;}
824  for (const auto & p : signalGammaCandPtrs_){ ret2.push_back(p); pt_index.push_back(std::make_pair(p->pt(),index)); index++;}
825  std::sort(pt_index.begin(),pt_index.end(),
826  boost::bind(&std::pair<float,size_t>::first,_1) >
827  boost::bind(&std::pair<float,size_t>::first,_2));
828  for( const auto & p : pt_index){
829  ret.push_back(ret2[p.second]);
830  }
831  return ret;
832  }
833 }
834 
837 reco::CandidatePtrVector Tau::signalChargedHadrCands() const {
838  std::vector<reco::PFCandidatePtr> r0 = signalPFChargedHadrCands();
839  if(signalChargedHadrCandPtrs_.isNull() || (!r0.empty() && r0.front().isAvailable())) {
841  for (const auto & p : r0) ret.push_back(p);
842  return ret;
843  } else {
844  return signalChargedHadrCandPtrs_;
845  }
846 }
847 
848 
851 reco::CandidatePtrVector Tau::signalNeutrHadrCands() const {
852  std::vector<reco::PFCandidatePtr> r0 = signalPFNeutrHadrCands();
853  if(signalNeutralHadrCandPtrs_.isNull() || (!r0.empty() && r0.front().isAvailable())) {
855  for (const auto & p : r0) ret.push_back(p);
856  return ret;
857  } else {
858  return signalNeutralHadrCandPtrs_;
859  }
860 }
861 
864 reco::CandidatePtrVector Tau::signalGammaCands() const {
865  std::vector<reco::PFCandidatePtr> r0 = signalPFGammaCands();
866  if(signalGammaCandPtrs_.isNull() || (!r0.empty() && r0.front().isAvailable())) {
868  for (const auto & p : r0) ret.push_back(p);
869  return ret;
870  } else {
871  return signalGammaCandPtrs_;
872  }
873 }
874 
877 reco::CandidatePtrVector Tau::isolationCands() const {
878  std::vector<reco::PFCandidatePtr> r0 = isolationPFCands();
880  if(!Tau::ExistIsolationCands() || (!r0.empty() && r0.front().isAvailable())) {
881  for (const auto & p : r0) ret.push_back(p);
882  return ret;
883  } else {
886  std::vector<std::pair<float,size_t> > pt_index;
887  size_t index=0;
888  for (const auto & p : isolationChargedHadrCandPtrs_){ ret2.push_back(p); pt_index.push_back(std::make_pair(p->pt(),index)); index++;}
889  for (const auto & p : isolationNeutralHadrCandPtrs_){ ret2.push_back(p); pt_index.push_back(std::make_pair(p->pt(),index)); index++;}
890  for (const auto & p : isolationGammaCandPtrs_){ ret2.push_back(p); pt_index.push_back(std::make_pair(p->pt(),index)); index++;}
891  std::sort(pt_index.begin(),pt_index.end(),
892  boost::bind(&std::pair<float,size_t>::first,_1) >
893  boost::bind(&std::pair<float,size_t>::first,_2));
894  for( const auto & p : pt_index){
895  ret.push_back(ret2[p.second]);
896  }
897  return ret;
898  }
899 }
900 
903 reco::CandidatePtrVector Tau::isolationChargedHadrCands() const {
904  std::vector<reco::PFCandidatePtr> r0 = isolationPFChargedHadrCands();
905  if(isolationChargedHadrCandPtrs_.isNull() || (!r0.empty() && r0.front().isAvailable())) {
907  for (const auto & p : r0) ret.push_back(p);
908  return ret;
909  } else {
910  return isolationChargedHadrCandPtrs_;
911  }
912 }
913 
916 reco::CandidatePtrVector Tau::isolationNeutrHadrCands() const {
918  std::vector<reco::PFCandidatePtr> r0 = isolationPFNeutrHadrCands();
919  if(isolationNeutralHadrCandPtrs_.isNull() || (!r0.empty() && r0.front().isAvailable())) {
921  for (const auto & p : r0) ret.push_back(p);
922  return ret;
923  } else {
924  return isolationNeutralHadrCandPtrs_;
925  }
926 }
927 
930 reco::CandidatePtrVector Tau::isolationGammaCands() const {
931  std::vector<reco::PFCandidatePtr> r0 = isolationPFGammaCands();
932  if(isolationGammaCandPtrs_.isNull() || (!r0.empty() && r0.front().isAvailable())) {
934  for (const auto & p : r0) ret.push_back(p);
935  return ret;
936  } else {
937  return isolationGammaCandPtrs_;
938  }
939 }
940 
941 
942 
945 size_t Tau::numberOfSourceCandidatePtrs() const {
946  if (Tau::ExistSignalCands()) return Tau::signalCands().size();
947  else if(pfSpecific_.empty()) return 0;
948  else return pfSpecific().selectedSignalPFCands_.size();
949 }
952  if (Tau::ExistSignalCands()) return Tau::signalCands()[i];
953  else if(pfSpecific_.empty()) return reco::CandidatePtr();
954  else return pfSpecific().selectedSignalPFCands_[i];
955 }
956 
957 
958 
959 
value_type const * get() const
Definition: RefToBase.h:212
virtual reco::TrackRef leadTrack() const
Definition: BaseTau.cc:26
int i
Definition: DBlmapReader.cc:9
virtual double p() const
magnitude of momentum vector
virtual const reco::TrackRefVector & isolationTracks() const
Definition: BaseTau.cc:30
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:139
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
bool isAvailable() const
Definition: Ptr.h:249
virtual void setP4(const LorentzVector &p4)
set 4-momentum
uint16_t size_type
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
static const int tauID
Definition: TopGenEvent.h:21
virtual double energy() const
energy
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Definition: BeamSpot.cc:71
Tau()
default constructor
Analysis-level lepton class.
Definition: Lepton.h:30
bool isNull() const
Checks for null.
Definition: Ptr.h:148
virtual CandidatePtr sourceCandidatePtr(size_type i) const
Definition: LeafCandidate.h:86
int j
Definition: DBlmapReader.cc:9
Jets made from MC generator particles.
Definition: GenJet.h:24
virtual const reco::TrackRefVector & signalTracks() const
Definition: BaseTau.cc:28
unsigned int index
Definition: LeafCandidate.h:31
void reserve(size_type n)
Reserve space for RefVector.
Definition: RefVector.h:95
Analysis-level tau class.
Definition: Tau.h:56
InputIterator leadPFCand(InputIterator begin, InputIterator end)
tuple out
Definition: dbtoconf.py:99
~Tau()
Definition: Tau.cc:26
virtual size_t numberOfSourceCandidatePtrs() const
Definition: LeafCandidate.h:83
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:19
edm::Ref< PFRecoTauChargedHadronCollection > PFRecoTauChargedHadronRef
presistent reference to a PFRecoTauChargedHadron
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
Tau()
Definition: Tau.h:16
value_type const at(size_type idx) const
Retrieve an element of the RefVector.
Definition: RefVector.h:76
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
tuple level
Definition: testEve_cfg.py:34
volatile std::atomic< bool > shutdown_flag false
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
virtual double phi() const
momentum azimuthal angle
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
math::ErrorF< 3 >::type CovMatrix