CMS 3D CMS Logo

PATTauProducer.cc
Go to the documentation of this file.
2 
8 
16 
22 
23 
26 
27 #include <vector>
28 #include <memory>
29 
30 using namespace pat;
31 
33  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false) ,
34  useUserData_(iConfig.exists("userData"))
35 {
36  firstOccurence_=true;
37  // initialize the configurables
38  baseTauToken_ = consumes<edm::View<reco::BaseTau> >(iConfig.getParameter<edm::InputTag>( "tauSource" ));
39  tauTransverseImpactParameterSrc_ = iConfig.getParameter<edm::InputTag>( "tauTransverseImpactParameterSource" );
40  tauTransverseImpactParameterToken_ = consumes<PFTauTIPAssociationByRef>( tauTransverseImpactParameterSrc_);
41  pfTauToken_ = consumes<reco::PFTauCollection>(iConfig.getParameter<edm::InputTag>( "tauSource" ));
42  caloTauToken_ = mayConsume<reco::CaloTauCollection>(iConfig.getParameter<edm::InputTag>( "tauSource" ));
43  embedIsolationTracks_ = iConfig.getParameter<bool>( "embedIsolationTracks" );
44  embedLeadTrack_ = iConfig.getParameter<bool>( "embedLeadTrack" );
45  embedSignalTracks_ = iConfig.getParameter<bool>( "embedSignalTracks" );
46  embedLeadPFCand_ = iConfig.getParameter<bool>( "embedLeadPFCand" );
47  embedLeadPFChargedHadrCand_ = iConfig.getParameter<bool>( "embedLeadPFChargedHadrCand" );
48  embedLeadPFNeutralCand_ = iConfig.getParameter<bool>( "embedLeadPFNeutralCand" );
49  embedSignalPFCands_ = iConfig.getParameter<bool>( "embedSignalPFCands" );
50  embedSignalPFChargedHadrCands_ = iConfig.getParameter<bool>( "embedSignalPFChargedHadrCands" );
51  embedSignalPFNeutralHadrCands_ = iConfig.getParameter<bool>( "embedSignalPFNeutralHadrCands" );
52  embedSignalPFGammaCands_ = iConfig.getParameter<bool>( "embedSignalPFGammaCands" );
53  embedIsolationPFCands_ = iConfig.getParameter<bool>( "embedIsolationPFCands" );
54  embedIsolationPFChargedHadrCands_ = iConfig.getParameter<bool>( "embedIsolationPFChargedHadrCands" );
55  embedIsolationPFNeutralHadrCands_ = iConfig.getParameter<bool>( "embedIsolationPFNeutralHadrCands" );
56  embedIsolationPFGammaCands_ = iConfig.getParameter<bool>( "embedIsolationPFGammaCands" );
57  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
58  if (addGenMatch_) {
59  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
60  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
61  genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection> >(iConfig.getParameter<edm::InputTag>( "genParticleMatch" )));
62  }
63  else {
64  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
65  }
66  }
67  addGenJetMatch_ = iConfig.getParameter<bool>( "addGenJetMatch" );
68  if(addGenJetMatch_) {
69  embedGenJetMatch_ = iConfig.getParameter<bool>( "embedGenJetMatch" );
70  genJetMatchToken_ = consumes<edm::Association<reco::GenJetCollection> >(iConfig.getParameter<edm::InputTag>( "genJetMatch" ));
71  }
72  addTauJetCorrFactors_ = iConfig.getParameter<bool>( "addTauJetCorrFactors" );
73  tauJetCorrFactorsTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "tauJetCorrFactorsSource" ), [this](edm::InputTag const & tag){return mayConsume<edm::ValueMap<TauJetCorrFactors> >(tag);});
74  // tau ID configurables
75  addTauID_ = iConfig.getParameter<bool>( "addTauID" );
76  if ( addTauID_ ) {
77  // read the different tau ID names
78  edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("tauIDSources");
79  std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
80  for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
81  tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
82  }
83  // but in any case at least once
84  if (tauIDSrcs_.empty()) throw cms::Exception("Configuration") <<
85  "PATTauProducer: id addTauID is true, you must specify either:\n" <<
86  "\tPSet tauIDSources = { \n" <<
87  "\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
88  "\t}\n";
89  }
90  caloTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<reco::CaloTauDiscriminator>(tag.second);});
91  pfTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<reco::PFTauDiscriminator>(tag.second);});
92  skipMissingTauID_ = iConfig.getParameter<bool>( "skipMissingTauID" );
93  // IsoDeposit configurables
94  if (iConfig.exists("isoDeposits")) {
95  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
96  if ( depconf.exists("tracker") ) isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
97  if ( depconf.exists("ecal") ) isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
98  if ( depconf.exists("hcal") ) isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
99  if ( depconf.exists("pfAllParticles") ) isoDepositLabels_.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
100  if ( depconf.exists("pfChargedHadron") ) isoDepositLabels_.push_back(std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadron")));
101  if ( depconf.exists("pfNeutralHadron") ) isoDepositLabels_.push_back(std::make_pair(pat::PfNeutralHadronIso,depconf.getParameter<edm::InputTag>("pfNeutralHadron")));
102  if ( depconf.exists("pfGamma") ) isoDepositLabels_.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfGamma")));
103 
104  if ( depconf.exists("user") ) {
105  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
106  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
107  int key = UserBaseIso;
108  for ( ; it != ed; ++it, ++key) {
109  isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
110  }
111  }
112  }
113  isoDepositTokens_ = edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys,edm::InputTag> const & label){return consumes<edm::ValueMap<IsoDeposit> >(label.second);});
114  // Efficiency configurables
115  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
116  if (addEfficiencies_) {
117  efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
118  }
119  // Resolution configurables
120  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
121  if (addResolutions_) {
123  }
124  // Check to see if the user wants to add user data
125  if ( useUserData_ ) {
126  userDataHelper_ = PATUserDataHelper<Tau>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
127  }
128  // produces vector of taus
129  produces<std::vector<Tau> >();
130 }
131 
133 {
134 }
135 
137 {
138  // switch off embedding (in unschedules mode)
139  if (iEvent.isRealData()){
140  addGenMatch_ = false;
141  embedGenMatch_ = false;
142  addGenJetMatch_ = false;
143  }
144 
145  // Get the collection of taus from the event
147  try {
148  iEvent.getByToken(baseTauToken_, anyTaus);
149  } catch (const edm::Exception &e) {
150  edm::LogWarning("DataSource") << "WARNING! No Tau collection found. This missing input will not block the job. Instead, an empty tau collection is being be produced.";
151  auto patTaus = std::make_unique<std::vector<Tau>>();
152  iEvent.put(std::move(patTaus));
153  return;
154  }
155 
156  if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
157 
159  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
160 
161  std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositTokens_.size());
162  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
163  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
164  }
165 
166  // prepare the MC matching
167  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > >genMatches(genMatchTokens_.size());
168  if (addGenMatch_) {
169  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
170  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
171  }
172  }
173 
175  if (addGenJetMatch_) iEvent.getByToken(genJetMatchToken_, genJetMatch);
176 
177  // read in the jet correction factors ValueMap
178  std::vector<edm::ValueMap<TauJetCorrFactors> > tauJetCorrs;
179  if (addTauJetCorrFactors_) {
180  for ( size_t i = 0; i < tauJetCorrFactorsTokens_.size(); ++i ) {
182  iEvent.getByToken(tauJetCorrFactorsTokens_[i], tauJetCorr);
183  tauJetCorrs.push_back( *tauJetCorr );
184  }
185  }
186 
187  auto patTaus = std::make_unique<std::vector<Tau>>();
188 
189  bool first=true; // this is introduced to issue warnings only for the first tau-jet
190  for (size_t idx = 0, ntaus = anyTaus->size(); idx < ntaus; ++idx) {
191  edm::RefToBase<reco::BaseTau> tausRef = anyTaus->refAt(idx);
192  edm::Ptr<reco::BaseTau> tausPtr = anyTaus->ptrAt(idx);
193 
194  Tau aTau(tausRef);
195  if (embedLeadTrack_) aTau.embedLeadTrack();
198  if (embedLeadPFCand_) {
199  if (aTau.isPFTau() )
200  aTau.embedLeadPFCand();
201  else
202  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
203  }
205  if (aTau.isPFTau() )
207  else
208  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
209  }
211  if (aTau.isPFTau() )
212  aTau.embedLeadPFNeutralCand();
213  else
214  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
215  }
216  if (embedSignalPFCands_) {
217  if (aTau.isPFTau() )
218  aTau.embedSignalPFCands();
219  else
220  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
221  }
223  if (aTau.isPFTau() )
225  else
226  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
227  }
229  if (aTau.isPFTau() )
231  else
232  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
233  }
235  if (aTau.isPFTau() )
237  else
238  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
239  }
241  if (aTau.isPFTau() )
242  aTau.embedIsolationPFCands();
243  else
244  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
245  }
247  if (aTau.isPFTau() )
249  else
250  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
251  }
253  if (aTau.isPFTau() )
255  else
256  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
257  }
259  if (aTau.isPFTau() )
261  else
262  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
263  }
264 
265  if (addTauJetCorrFactors_) {
266  // add additional JetCorrs to the jet
267  for ( unsigned int i=0; i<tauJetCorrs.size(); ++i ) {
268  const TauJetCorrFactors& tauJetCorr = tauJetCorrs[i][tausRef];
269  // uncomment for debugging
270  // tauJetCorr.print();
271  aTau.addJECFactors(tauJetCorr);
272  }
273  std::vector<std::string> levels = tauJetCorrs[0][tausRef].correctionLabels();
274  if(std::find(levels.begin(), levels.end(), "L2L3Residual")!=levels.end()){
275  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L2L3Residual"));
276  }
277  else if(std::find(levels.begin(), levels.end(), "L3Absolute")!=levels.end()){
278  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L3Absolute"));
279  }
280  else{
281  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("Uncorrected"));
282  if(first){
283  edm::LogWarning("L3Absolute not found")
284  << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
285  << "of module " << tauJetCorrs[0][tausRef].jecSet() << " jets will remain"
286  << " uncorrected.";
287  first=false;
288  }
289  }
290  }
291 
292  // store the match to the generated final state muons
293  if (addGenMatch_) {
294  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
295  reco::GenParticleRef genTau = (*genMatches[i])[tausRef];
296  aTau.addGenParticleRef(genTau);
297  }
298  if (embedGenMatch_) aTau.embedGenParticle();
299  }
300 
301  // store the match to the visible part of the generated tau
302  if (addGenJetMatch_) {
303  reco::GenJetRef genJetTau = (*genJetMatch)[tausRef];
304  if (genJetTau.isNonnull() && genJetTau.isAvailable() ) {
305  aTau.setGenJet( genJetTau );
306  } // leave empty if no match found
307  }
308 
309  // prepare ID extraction
310  if ( addTauID_ ) {
311  std::string missingDiscriminators;
312  std::vector<pat::Tau::IdPair> ids(tauIDSrcs_.size());
313  auto const& tausDeref = *tausRef;
314  for ( size_t i = 0; i < tauIDSrcs_.size(); ++i ) {
315  if ( typeid(tausDeref) == typeid(reco::PFTau) ) {
316  //std::cout << "filling PFTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
317  edm::Handle<reco::PFTauCollection> pfTauCollection;
318  iEvent.getByToken(pfTauToken_, pfTauCollection);
319 
321  iEvent.getByToken(pfTauIDTokens_[i], pfTauIdDiscr);
322 
323  if(skipMissingTauID_ && !pfTauIdDiscr.isValid()){
324  if(!missingDiscriminators.empty()){
325  missingDiscriminators+=", ";
326  }
327  missingDiscriminators+=tauIDSrcs_[i].first;
328  continue;
329  }
330  ids[i].first = tauIDSrcs_[i].first;
331  ids[i].second = getTauIdDiscriminator(pfTauCollection, idx, pfTauIdDiscr);
332  } else if ( typeid(tausDeref) == typeid(reco::CaloTau) ) {
333  //std::cout << "filling CaloTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
334  edm::Handle<reco::CaloTauCollection> caloTauCollection;
335  iEvent.getByToken(caloTauToken_, caloTauCollection);
336 
338  iEvent.getByToken(caloTauIDTokens_[i], caloTauIdDiscr);
339 
340  if(skipMissingTauID_ && !caloTauIdDiscr.isValid()){
341  if(!missingDiscriminators.empty()){
342  missingDiscriminators+=", ";
343  }
344  missingDiscriminators+=tauIDSrcs_[i].first;
345  continue;
346  }
347  ids[i].first = tauIDSrcs_[i].first;
348  ids[i].second = getTauIdDiscriminator(caloTauCollection, idx, caloTauIdDiscr);
349  } else {
350  throw cms::Exception("Type Mismatch") <<
351  "PATTauProducer: unsupported datatype '" << typeid(tausDeref).name() << "' for tauSource\n";
352  }
353  }
354  if(!missingDiscriminators.empty() && firstOccurence_){
355  edm::LogWarning("DataSource") << "The following tau discriminators have not been found in the event:\n"
356  << missingDiscriminators <<"\n"
357  << "They will not be embedded into the pat::Tau object.\n"
358  << "Note: this message will be printed only at first occurence.";
359  firstOccurence_=false;
360  }
361  aTau.setTauIDs(ids);
362  }
363 
364  // extraction of reconstructed tau decay mode
365  // (only available for PFTaus)
366  if ( aTau.isPFTau() ) {
368  iEvent.getByToken(pfTauToken_, pfTaus);
369  reco::PFTauRef pfTauRef(pfTaus, idx);
370 
371  aTau.setDecayMode(pfTauRef->decayMode());
372  }
373 
374  // extraction of variables needed to rerun MVA isolation and anti-electron discriminator on MiniAOD
375  if( !aTau.pfEssential_.empty() ) {
377  iEvent.getByToken(pfTauToken_, pfTaus);
378  reco::PFTauRef pfTauRef(pfTaus, idx);
379  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
380  float ecalEnergy = 0;
381  float hcalEnergy = 0;
382  float sumPhiTimesEnergy = 0.;
383  float sumEtaTimesEnergy = 0.;
384  float sumEnergy = 0.;
385  float leadChargedCandPt = -99;
386  float leadChargedCandEtaAtEcalEntrance = -99;
387  const std::vector<reco::CandidatePtr>& signalCands = pfTauRef->signalCands();
388  for(const auto& it : signalCands) {
389  const reco::PFCandidate* icand = dynamic_cast<const reco::PFCandidate*>(it.get());
390  if (icand != nullptr) {
391  ecalEnergy += icand->ecalEnergy();
392  hcalEnergy += icand->hcalEnergy();
393  sumPhiTimesEnergy += icand->positionAtECALEntrance().phi()*icand->energy();
394  sumEtaTimesEnergy += icand->positionAtECALEntrance().eta()*icand->energy();
395  sumEnergy += icand->energy();
396  const reco::Track* track = nullptr;
397  if ( icand->trackRef().isNonnull() ) track = icand->trackRef().get();
398  else if ( icand->muonRef().isNonnull() && icand->muonRef()->innerTrack().isNonnull() ) track = icand->muonRef ()->innerTrack().get();
399  else if ( icand->muonRef().isNonnull() && icand->muonRef()->globalTrack().isNonnull() ) track = icand->muonRef ()->globalTrack().get();
400  else if ( icand->muonRef().isNonnull() && icand->muonRef()->outerTrack().isNonnull() ) track = icand->muonRef ()->outerTrack().get();
401  else if ( icand->gsfTrackRef().isNonnull() ) track = icand->gsfTrackRef().get();
402  if( track ) {
403  if( track->pt() > leadChargedCandPt ) {
404  leadChargedCandEtaAtEcalEntrance = icand->positionAtECALEntrance().eta();
405  leadChargedCandPt = track->pt();
406  }
407  }
408  }
409  else {
410  // TauReco@MiniAOD: individual ECAL and HCAL energies currently not available for PackedCandidates
411  // (see above implementation for PFCandidates).
412  // Should be added if available, as well as on-the-fly computation of position at ECAL entrance
413  sumEnergy += it->energy();
414  const reco::Track* track = it->bestTrack();
415  if( track != nullptr ) {
416  if( track->pt() > leadChargedCandPt ) {
417  leadChargedCandPt = track->pt();
418  }
419  }
420  }
421  }
422  aTauPFEssential.ecalEnergy_ = ecalEnergy;
423  aTauPFEssential.hcalEnergy_ = hcalEnergy;
424  aTauPFEssential.ptLeadChargedCand_ = leadChargedCandPt;
425  aTauPFEssential.etaAtEcalEntranceLeadChargedCand_ = leadChargedCandEtaAtEcalEntrance;
426  if (sumEnergy != 0.) {
427  aTauPFEssential.phiAtEcalEntrance_ = sumPhiTimesEnergy/sumEnergy;
428  aTauPFEssential.etaAtEcalEntrance_ = sumEtaTimesEnergy/sumEnergy;
429  }
430  else {
431  aTauPFEssential.phiAtEcalEntrance_ = -99.;
432  aTauPFEssential.etaAtEcalEntrance_ = -99.;
433  }
434  float leadingTrackNormChi2 = 0;
435  float ecalEnergyLeadChargedHadrCand = -99.;
436  float hcalEnergyLeadChargedHadrCand = -99.;
437  float emFraction = -1.;
438  float myHCALenergy = 0.;
439  float myECALenergy = 0.;
440  const reco::CandidatePtr& leadingPFCharged = pfTauRef->leadChargedHadrCand();
441  if(leadingPFCharged.isNonnull()) {
442  const reco::PFCandidate* pfCandPtr = dynamic_cast<const reco::PFCandidate*>(leadingPFCharged.get());
443  if(pfCandPtr != nullptr) { // PFTau made from PFCandidates
444  ecalEnergyLeadChargedHadrCand = pfCandPtr->ecalEnergy();
445  hcalEnergyLeadChargedHadrCand = pfCandPtr->hcalEnergy();
446  reco::TrackRef trackRef = pfCandPtr->trackRef();
447  if( trackRef.isNonnull() ) {
448  leadingTrackNormChi2 = trackRef->normalizedChi2();
449  for(const auto& isoPFCand : pfTauRef->isolationPFCands()){
450  myHCALenergy += isoPFCand->hcalEnergy();
451  myECALenergy += isoPFCand->ecalEnergy();
452  }
453  for(const auto& signalPFCand : pfTauRef->signalPFCands()){
454  myHCALenergy += signalPFCand->hcalEnergy();
455  myECALenergy += signalPFCand->ecalEnergy();
456  }
457  if( myHCALenergy + myECALenergy != 0. ) {
458  emFraction = myECALenergy/( myHCALenergy + myECALenergy);
459  }
460  }
461  }
462  else {
463  const pat::PackedCandidate* packedCandPtr = dynamic_cast<const pat::PackedCandidate*>(leadingPFCharged.get());
464  if (packedCandPtr != nullptr) {
465  // TauReco@MiniAOD: Update code below if ecal/hcal energies are available.
466  const reco::Track* track = packedCandPtr->hasTrackDetails() ? &packedCandPtr->pseudoTrack() : nullptr;
467  if (track != nullptr) {
468  leadingTrackNormChi2 = track->normalizedChi2();
469  }
470  }
471  }
472  }
473 
474  aTauPFEssential.emFraction_ = emFraction;
475  aTauPFEssential.leadingTrackNormChi2_ = leadingTrackNormChi2;
476  aTauPFEssential.ecalEnergyLeadChargedHadrCand_ = ecalEnergyLeadChargedHadrCand;
477  aTauPFEssential.hcalEnergyLeadChargedHadrCand_ = hcalEnergyLeadChargedHadrCand;
478  // extraction of tau lifetime information
479  if( !tauTransverseImpactParameterSrc_.label().empty() ) {
480  edm::Handle<PFTauTIPAssociationByRef> tauLifetimeInfos;
481  iEvent.getByToken(tauTransverseImpactParameterToken_, tauLifetimeInfos);
482  const reco::PFTauTransverseImpactParameter& tauLifetimeInfo = *(*tauLifetimeInfos)[pfTauRef];
483  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
484  aTauPFEssential.dxy_PCA_ = tauLifetimeInfo.dxy_PCA();
485  aTauPFEssential.dxy_ = tauLifetimeInfo.dxy();
486  aTauPFEssential.dxy_error_ = tauLifetimeInfo.dxy_error();
487  aTauPFEssential.hasSV_ = tauLifetimeInfo.hasSecondaryVertex();
488  aTauPFEssential.flightLength_ = tauLifetimeInfo.flightLength();
489  aTauPFEssential.flightLengthSig_ = tauLifetimeInfo.flightLengthSig();
490  aTauPFEssential.ip3d_ = tauLifetimeInfo.ip3d();
491  aTauPFEssential.ip3d_error_ = tauLifetimeInfo.ip3d_error();
492  }
493  }
494 
495  // Isolation
496  if (isolator_.enabled()) {
498  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
499  // better to loop backwards, so the vector is resized less times
500  for ( IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
501  ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
502  aTau.setIsolation(it->first, it->second);
503  }
504  }
505 
506  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
507  aTau.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[tausRef]);
508  }
509 
510  if (efficiencyLoader_.enabled()) {
511  efficiencyLoader_.setEfficiencies( aTau, tausRef );
512  }
513 
514  if (resolutionLoader_.enabled()) {
516  }
517 
518  if ( useUserData_ ) {
519  userDataHelper_.add( aTau, iEvent, iSetup );
520  }
521 
522  patTaus->push_back(aTau);
523  }
524 
525  // sort taus in pT
526  std::sort(patTaus->begin(), patTaus->end(), pTTauComparator_);
527 
528  // put genEvt object in Event
529  iEvent.put(std::move(patTaus));
530 
531  // clean up
533 }
534 
535 template <typename TauCollectionType, typename TauDiscrType>
536 float PATTauProducer::getTauIdDiscriminator(const edm::Handle<TauCollectionType>& tauCollection, size_t tauIdx, const edm::Handle<TauDiscrType>& tauIdDiscr)
537 {
538  edm::Ref<TauCollectionType> tauRef(tauCollection, tauIdx);
539  return (*tauIdDiscr)[tauRef];
540 }
541 
542 // ParameterSet description for module
544 {
546  iDesc.setComment("PAT tau producer module");
547 
548  // input source
549  iDesc.add<edm::InputTag>("tauSource", edm::InputTag())->setComment("input collection");
550 
551  // embedding
552  iDesc.add<bool>("embedIsolationTracks", false)->setComment("embed external isolation tracks");
553  iDesc.add<bool>("embedLeadTrack", false)->setComment("embed external leading track");
554  iDesc.add<bool>("embedLeadTracks", false)->setComment("embed external signal tracks");
555 
556  // MC matching configurables
557  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
558  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
559  std::vector<edm::InputTag> emptySourceVector;
560  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
561  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
562  )->setComment("input with MC match information");
563 
564  // MC jet matching variables
565  iDesc.add<bool>("addGenJetMatch", true)->setComment("add MC jet matching");
566  iDesc.add<bool>("embedGenJetMatch", false)->setComment("embed MC jet matched jet information");
567  iDesc.add<edm::InputTag>("genJetMatch", edm::InputTag("tauGenJetMatch"));
568 
569 
571 
572  // tau ID configurables
573  iDesc.add<bool>("addTauID", true)->setComment("add tau ID variables");
574  edm::ParameterSetDescription tauIDSourcesPSet;
575  tauIDSourcesPSet.setAllowAnything();
576  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("tauIDSource", edm::InputTag(), true) xor
577  edm::ParameterDescription<edm::ParameterSetDescription>("tauIDSources", tauIDSourcesPSet, true)
578  )->setComment("input with tau ID variables");
579  // (Dis)allow to skip missing tauId sources
580  iDesc.add<bool>("skipMissingTauID", false)->setComment("allow to skip a tau ID variable when not present in the event");
581 
582  // IsoDeposit configurables
583  edm::ParameterSetDescription isoDepositsPSet;
584  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
585  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
586  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
587  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
588  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadron");
589  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadron");
590  isoDepositsPSet.addOptional<edm::InputTag>("pfGamma");
591  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
592  iDesc.addOptional("isoDeposits", isoDepositsPSet);
593 
594  // Efficiency configurables
595  edm::ParameterSetDescription efficienciesPSet;
596  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
597  iDesc.add("efficiencies", efficienciesPSet);
598  iDesc.add<bool>("addEfficiencies", false);
599 
600  // Check to see if the user wants to add user data
601  edm::ParameterSetDescription userDataPSet;
603  iDesc.addOptional("userData", userDataPSet);
604 
605  edm::ParameterSetDescription isolationPSet;
606  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
607  iDesc.add("userIsolation", isolationPSet);
608 
609 }
610 
612 
614 
615 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
~PATTauProducer() override
bool isAvailable() const
Definition: Ref.h:575
T getParameter(std::string const &) const
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:222
void setComment(std::string const &value)
Assists in assimilating all pat::UserData into pat objects.
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
std::pair< std::string, edm::InputTag > NameTag
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:99
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
void embedIsolationPFCands()
method to store the isolation candidates internally
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:594
void embedIsolationPFGammaCands()
method to store the isolation gamma candidates internally
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void setAllowAnything()
allow any parameter label/value pairs
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
pat::helper::EfficiencyLoader efficiencyLoader_
void embedLeadTrack()
method to store the leading track internally
bool exists(std::string const &parameterName) const
checks if a parameter exists
void embedSignalPFChargedHadrCands()
method to store the signal charged hadrons candidates internally
pat::helper::KinResolutionsLoader resolutionLoader_
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
float getTauIdDiscriminator(const edm::Handle< TauCollectionType > &, size_t, const edm::Handle< TauDiscrType > &)
void setDecayMode(int)
set decay mode
void setTauIDs(const std::vector< IdPair > &ids)
Definition: Tau.h:385
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
bool isRealData() const
Definition: EventBase.h:62
const std::string names[nVars_]
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:368
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: Lepton.h:176
bool embedIsolationPFChargedHadrCands_
Definition: HeavyIon.h:7
static void fillDescription(edm::ParameterSetDescription &iDesc)
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:169
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:50
char const * label
void setComment(std::string const &value)
void embedSignalPFCands()
method to store the signal candidates internally
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
edm::EDGetTokenT< PFTauTIPAssociationByRef > tauTransverseImpactParameterToken_
pat::helper::MultiIsolator isolator_
void embedGenParticle()
Definition: PATObject.h:694
edm::EDGetTokenT< edm::View< reco::BaseTau > > baseTauToken_
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
bool embedIsolationPFNeutralHadrCands_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double pt() const
track transverse momentum
Definition: TrackBase.h:654
edm::EDGetTokenT< reco::CaloTauCollection > caloTauToken_
double energy() const final
energy
pat::PATUserDataHelper< pat::Tau > userDataHelper_
virtual const reco::Track & pseudoTrack() const
genJetMatch
switch on/off embedding of matched genJet&#39;s
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
bool embedSignalPFNeutralHadrCands_
std::vector< pat::tau::TauPFEssential > pfEssential_
Definition: Tau.h:536
void embedIsolationPFNeutralHadrCands()
method to store the isolation neutral hadrons candidates internally
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void embedLeadPFChargedHadrCand()
method to store the leading charged hadron candidate internally
bool isValid() const
Definition: HandleBase.h:74
void embedIsolationPFChargedHadrCands()
method to store the isolation charged hadrons candidates internally
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
void setGenJet(const reco::GenJetRef &ref)
set the matched GenJet
Definition: Tau.py:1
void embedLeadPFNeutralCand()
method to store the leading neutral candidate internally
std::vector< edm::EDGetTokenT< reco::CaloTauDiscriminator > > caloTauIDTokens_
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:678
std::vector< edm::EDGetTokenT< edm::ValueMap< TauJetCorrFactors > > > tauJetCorrFactorsTokens_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
edm::InputTag tauTransverseImpactParameterSrc_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
std::string const & label() const
Definition: InputTag.h:36
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void initializeJEC(unsigned int level, const unsigned int set=0)
initialize the jet to a given JEC level during creation starting from Uncorrected ...
void embedSignalPFNeutralHadrCands()
method to store the signal neutral hadrons candidates internally
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:16
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
void addJECFactors(const TauJetCorrFactors &jec)
add more sets of energy correction factors
Definition: Tau.h:450
PATTauProducer(const edm::ParameterSet &iConfig)
HLT enums.
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:480
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:232
void embedSignalTracks()
method to store the signal tracks internally
bool isPFTau() const
Returns true if this pat::Tau was made from a reco::PFTau.
Definition: Tau.h:158
void embedSignalPFGammaCands()
method to store the signal gamma candidates internally
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
bool embedSignalPFChargedHadrCands_
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > pfTauIDTokens_
void embedIsolationTracks()
method to store the isolation tracks internally
std::vector< NameTag > tauIDSrcs_
edm::EDGetTokenT< reco::PFTauCollection > pfTauToken_
def move(src, dest)
Definition: eostools.py:511
GreaterByPt< Tau > pTTauComparator_
Produces pat::Tau&#39;s.
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:82
void embedLeadPFCand()