CMS 3D CMS Logo

PATTauProducer.cc
Go to the documentation of this file.
2 
8 
16 
21 
22 
25 
26 #include <vector>
27 #include <memory>
28 
29 using namespace pat;
30 
32  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false) ,
33  useUserData_(iConfig.exists("userData"))
34 {
35  firstOccurence_=true;
36  // initialize the configurables
37  baseTauToken_ = consumes<edm::View<reco::BaseTau> >(iConfig.getParameter<edm::InputTag>( "tauSource" ));
38  tauTransverseImpactParameterSrc_ = iConfig.getParameter<edm::InputTag>( "tauTransverseImpactParameterSource" );
39  tauTransverseImpactParameterToken_ = consumes<PFTauTIPAssociationByRef>( tauTransverseImpactParameterSrc_);
40  pfTauToken_ = consumes<reco::PFTauCollection>(iConfig.getParameter<edm::InputTag>( "tauSource" ));
41  caloTauToken_ = mayConsume<reco::CaloTauCollection>(iConfig.getParameter<edm::InputTag>( "tauSource" ));
42  embedIsolationTracks_ = iConfig.getParameter<bool>( "embedIsolationTracks" );
43  embedLeadTrack_ = iConfig.getParameter<bool>( "embedLeadTrack" );
44  embedSignalTracks_ = iConfig.getParameter<bool>( "embedSignalTracks" );
45  embedLeadPFCand_ = iConfig.getParameter<bool>( "embedLeadPFCand" );
46  embedLeadPFChargedHadrCand_ = iConfig.getParameter<bool>( "embedLeadPFChargedHadrCand" );
47  embedLeadPFNeutralCand_ = iConfig.getParameter<bool>( "embedLeadPFNeutralCand" );
48  embedSignalPFCands_ = iConfig.getParameter<bool>( "embedSignalPFCands" );
49  embedSignalPFChargedHadrCands_ = iConfig.getParameter<bool>( "embedSignalPFChargedHadrCands" );
50  embedSignalPFNeutralHadrCands_ = iConfig.getParameter<bool>( "embedSignalPFNeutralHadrCands" );
51  embedSignalPFGammaCands_ = iConfig.getParameter<bool>( "embedSignalPFGammaCands" );
52  embedIsolationPFCands_ = iConfig.getParameter<bool>( "embedIsolationPFCands" );
53  embedIsolationPFChargedHadrCands_ = iConfig.getParameter<bool>( "embedIsolationPFChargedHadrCands" );
54  embedIsolationPFNeutralHadrCands_ = iConfig.getParameter<bool>( "embedIsolationPFNeutralHadrCands" );
55  embedIsolationPFGammaCands_ = iConfig.getParameter<bool>( "embedIsolationPFGammaCands" );
56  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
57  if (addGenMatch_) {
58  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
59  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
60  genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection> >(iConfig.getParameter<edm::InputTag>( "genParticleMatch" )));
61  }
62  else {
63  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
64  }
65  }
66  addGenJetMatch_ = iConfig.getParameter<bool>( "addGenJetMatch" );
67  if(addGenJetMatch_) {
68  embedGenJetMatch_ = iConfig.getParameter<bool>( "embedGenJetMatch" );
69  genJetMatchToken_ = consumes<edm::Association<reco::GenJetCollection> >(iConfig.getParameter<edm::InputTag>( "genJetMatch" ));
70  }
71  addTauJetCorrFactors_ = iConfig.getParameter<bool>( "addTauJetCorrFactors" );
72  tauJetCorrFactorsTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "tauJetCorrFactorsSource" ), [this](edm::InputTag const & tag){return mayConsume<edm::ValueMap<TauJetCorrFactors> >(tag);});
73  // tau ID configurables
74  addTauID_ = iConfig.getParameter<bool>( "addTauID" );
75  if ( addTauID_ ) {
76  // read the different tau ID names
77  edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("tauIDSources");
78  std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
79  for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
80  tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
81  }
82  // but in any case at least once
83  if (tauIDSrcs_.empty()) throw cms::Exception("Configuration") <<
84  "PATTauProducer: id addTauID is true, you must specify either:\n" <<
85  "\tPSet tauIDSources = { \n" <<
86  "\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
87  "\t}\n";
88  }
89  caloTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<reco::CaloTauDiscriminator>(tag.second);});
90  pfTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<reco::PFTauDiscriminator>(tag.second);});
91  skipMissingTauID_ = iConfig.getParameter<bool>( "skipMissingTauID" );
92  // IsoDeposit configurables
93  if (iConfig.exists("isoDeposits")) {
94  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
95  if ( depconf.exists("tracker") ) isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
96  if ( depconf.exists("ecal") ) isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
97  if ( depconf.exists("hcal") ) isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
98  if ( depconf.exists("pfAllParticles") ) isoDepositLabels_.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
99  if ( depconf.exists("pfChargedHadron") ) isoDepositLabels_.push_back(std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadron")));
100  if ( depconf.exists("pfNeutralHadron") ) isoDepositLabels_.push_back(std::make_pair(pat::PfNeutralHadronIso,depconf.getParameter<edm::InputTag>("pfNeutralHadron")));
101  if ( depconf.exists("pfGamma") ) isoDepositLabels_.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfGamma")));
102 
103  if ( depconf.exists("user") ) {
104  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
105  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
106  int key = UserBaseIso;
107  for ( ; it != ed; ++it, ++key) {
108  isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
109  }
110  }
111  }
112  isoDepositTokens_ = edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys,edm::InputTag> const & label){return consumes<edm::ValueMap<IsoDeposit> >(label.second);});
113  // Efficiency configurables
114  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
115  if (addEfficiencies_) {
116  efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
117  }
118  // Resolution configurables
119  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
120  if (addResolutions_) {
122  }
123  // Check to see if the user wants to add user data
124  if ( useUserData_ ) {
125  userDataHelper_ = PATUserDataHelper<Tau>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
126  }
127  // produces vector of taus
128  produces<std::vector<Tau> >();
129 }
130 
132 {
133 }
134 
136 {
137  // switch off embedding (in unschedules mode)
138  if (iEvent.isRealData()){
139  addGenMatch_ = false;
140  embedGenMatch_ = false;
141  addGenJetMatch_ = false;
142  }
143 
144  // Get the collection of taus from the event
146  try {
147  iEvent.getByToken(baseTauToken_, anyTaus);
148  } catch (const edm::Exception &e) {
149  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.";
150  auto patTaus = std::make_unique<std::vector<Tau>>();
151  iEvent.put(std::move(patTaus));
152  return;
153  }
154 
155  if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
156 
158  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
159 
160  std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositTokens_.size());
161  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
162  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
163  }
164 
165  // prepare the MC matching
166  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > >genMatches(genMatchTokens_.size());
167  if (addGenMatch_) {
168  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
169  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
170  }
171  }
172 
174  if (addGenJetMatch_) iEvent.getByToken(genJetMatchToken_, genJetMatch);
175 
176  // read in the jet correction factors ValueMap
177  std::vector<edm::ValueMap<TauJetCorrFactors> > tauJetCorrs;
178  if (addTauJetCorrFactors_) {
179  for ( size_t i = 0; i < tauJetCorrFactorsTokens_.size(); ++i ) {
181  iEvent.getByToken(tauJetCorrFactorsTokens_[i], tauJetCorr);
182  tauJetCorrs.push_back( *tauJetCorr );
183  }
184  }
185 
186  auto patTaus = std::make_unique<std::vector<Tau>>();
187 
188  bool first=true; // this is introduced to issue warnings only for the first tau-jet
189  for (size_t idx = 0, ntaus = anyTaus->size(); idx < ntaus; ++idx) {
190  edm::RefToBase<reco::BaseTau> tausRef = anyTaus->refAt(idx);
191  edm::Ptr<reco::BaseTau> tausPtr = anyTaus->ptrAt(idx);
192 
193  Tau aTau(tausRef);
194  if (embedLeadTrack_) aTau.embedLeadTrack();
197  if (embedLeadPFCand_) {
198  if (aTau.isPFTau() )
199  aTau.embedLeadPFCand();
200  else
201  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
202  }
204  if (aTau.isPFTau() )
206  else
207  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
208  }
210  if (aTau.isPFTau() )
211  aTau.embedLeadPFNeutralCand();
212  else
213  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
214  }
215  if (embedSignalPFCands_) {
216  if (aTau.isPFTau() )
217  aTau.embedSignalPFCands();
218  else
219  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
220  }
222  if (aTau.isPFTau() )
224  else
225  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
226  }
228  if (aTau.isPFTau() )
230  else
231  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
232  }
234  if (aTau.isPFTau() )
236  else
237  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
238  }
240  if (aTau.isPFTau() )
241  aTau.embedIsolationPFCands();
242  else
243  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
244  }
246  if (aTau.isPFTau() )
248  else
249  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
250  }
252  if (aTau.isPFTau() )
254  else
255  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
256  }
258  if (aTau.isPFTau() )
260  else
261  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
262  }
263 
264  if (addTauJetCorrFactors_) {
265  // add additional JetCorrs to the jet
266  for ( unsigned int i=0; i<tauJetCorrs.size(); ++i ) {
267  const TauJetCorrFactors& tauJetCorr = tauJetCorrs[i][tausRef];
268  // uncomment for debugging
269  // tauJetCorr.print();
270  aTau.addJECFactors(tauJetCorr);
271  }
272  std::vector<std::string> levels = tauJetCorrs[0][tausRef].correctionLabels();
273  if(std::find(levels.begin(), levels.end(), "L2L3Residual")!=levels.end()){
274  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L2L3Residual"));
275  }
276  else if(std::find(levels.begin(), levels.end(), "L3Absolute")!=levels.end()){
277  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L3Absolute"));
278  }
279  else{
280  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("Uncorrected"));
281  if(first){
282  edm::LogWarning("L3Absolute not found")
283  << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
284  << "of module " << tauJetCorrs[0][tausRef].jecSet() << " jets will remain"
285  << " uncorrected.";
286  first=false;
287  }
288  }
289  }
290 
291  // store the match to the generated final state muons
292  if (addGenMatch_) {
293  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
294  reco::GenParticleRef genTau = (*genMatches[i])[tausRef];
295  aTau.addGenParticleRef(genTau);
296  }
297  if (embedGenMatch_) aTau.embedGenParticle();
298  }
299 
300  // store the match to the visible part of the generated tau
301  if (addGenJetMatch_) {
302  reco::GenJetRef genJetTau = (*genJetMatch)[tausRef];
303  if (genJetTau.isNonnull() && genJetTau.isAvailable() ) {
304  aTau.setGenJet( genJetTau );
305  } // leave empty if no match found
306  }
307 
308  // prepare ID extraction
309  if ( addTauID_ ) {
310  std::string missingDiscriminators;
311  std::vector<pat::Tau::IdPair> ids(tauIDSrcs_.size());
312  auto const& tausDeref = *tausRef;
313  for ( size_t i = 0; i < tauIDSrcs_.size(); ++i ) {
314  if ( typeid(tausDeref) == typeid(reco::PFTau) ) {
315  //std::cout << "filling PFTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
316  edm::Handle<reco::PFTauCollection> pfTauCollection;
317  iEvent.getByToken(pfTauToken_, pfTauCollection);
318 
320  iEvent.getByToken(pfTauIDTokens_[i], pfTauIdDiscr);
321 
322  if(skipMissingTauID_ && !pfTauIdDiscr.isValid()){
323  if(!missingDiscriminators.empty()){
324  missingDiscriminators+=", ";
325  }
326  missingDiscriminators+=tauIDSrcs_[i].first;
327  continue;
328  }
329  ids[i].first = tauIDSrcs_[i].first;
330  ids[i].second = getTauIdDiscriminator(pfTauCollection, idx, pfTauIdDiscr);
331  } else if ( typeid(tausDeref) == typeid(reco::CaloTau) ) {
332  //std::cout << "filling CaloTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
333  edm::Handle<reco::CaloTauCollection> caloTauCollection;
334  iEvent.getByToken(caloTauToken_, caloTauCollection);
335 
337  iEvent.getByToken(caloTauIDTokens_[i], caloTauIdDiscr);
338 
339  if(skipMissingTauID_ && !caloTauIdDiscr.isValid()){
340  if(!missingDiscriminators.empty()){
341  missingDiscriminators+=", ";
342  }
343  missingDiscriminators+=tauIDSrcs_[i].first;
344  continue;
345  }
346  ids[i].first = tauIDSrcs_[i].first;
347  ids[i].second = getTauIdDiscriminator(caloTauCollection, idx, caloTauIdDiscr);
348  } else {
349  throw cms::Exception("Type Mismatch") <<
350  "PATTauProducer: unsupported datatype '" << typeid(tausDeref).name() << "' for tauSource\n";
351  }
352  }
353  if(!missingDiscriminators.empty() && firstOccurence_){
354  edm::LogWarning("DataSource") << "The following tau discriminators have not been found in the event:\n"
355  << missingDiscriminators <<"\n"
356  << "They will not be embedded into the pat::Tau object.\n"
357  << "Note: this message will be printed only at first occurence.";
358  firstOccurence_=false;
359  }
360  aTau.setTauIDs(ids);
361  }
362 
363  // extraction of reconstructed tau decay mode
364  // (only available for PFTaus)
365  if ( aTau.isPFTau() ) {
367  iEvent.getByToken(pfTauToken_, pfTaus);
368  reco::PFTauRef pfTauRef(pfTaus, idx);
369 
370  aTau.setDecayMode(pfTauRef->decayMode());
371  }
372 
373  // extraction of variables needed to rerun MVA isolation and anti-electron discriminator on MiniAOD
374  if( aTau.isPFTau() ) {
376  iEvent.getByToken(pfTauToken_, pfTaus);
377  reco::PFTauRef pfTauRef(pfTaus, idx);
378  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
379  float ecalEnergy = 0;
380  float hcalEnergy = 0;
381  float sumPhiTimesEnergy = 0.;
382  float sumEtaTimesEnergy = 0.;
383  float sumEnergy = 0.;
384  float leadChargedCandPt = -99;
385  float leadChargedCandEtaAtEcalEntrance = -99;
386  const std::vector<reco::PFCandidatePtr>& signalCands = pfTauRef->signalPFCands();
387  for(std::vector<reco::PFCandidatePtr>::const_iterator it = signalCands.begin(); it != signalCands.end(); ++it) {
388  const reco::PFCandidatePtr& icand = *it;
389  ecalEnergy += icand->ecalEnergy();
390  hcalEnergy += icand->hcalEnergy();
391  sumPhiTimesEnergy += icand->positionAtECALEntrance().phi()*icand->energy();
392  sumEtaTimesEnergy += icand->positionAtECALEntrance().eta()*icand->energy();
393  sumEnergy += icand->energy();
394  const reco::Track* track = nullptr;
395  if ( icand->trackRef().isNonnull() ) track = icand->trackRef().get();
396  else if ( icand->muonRef().isNonnull() && icand->muonRef()->innerTrack().isNonnull() ) track = icand->muonRef()->innerTrack().get();
397  else if ( icand->muonRef().isNonnull() && icand->muonRef()->globalTrack().isNonnull() ) track = icand->muonRef()->globalTrack().get();
398  else if ( icand->muonRef().isNonnull() && icand->muonRef()->outerTrack().isNonnull() ) track = icand->muonRef()->outerTrack().get();
399  else if ( icand->gsfTrackRef().isNonnull() ) track = icand->gsfTrackRef().get();
400  if( track ) {
401  if( track->pt() > leadChargedCandPt ) {
402  leadChargedCandEtaAtEcalEntrance = icand->positionAtECALEntrance().eta();
403  leadChargedCandPt = track->pt();
404  }
405  }
406  }
407  aTauPFEssential.ecalEnergy_ = ecalEnergy;
408  aTauPFEssential.hcalEnergy_ = hcalEnergy;
409  aTauPFEssential.ptLeadChargedCand_ = leadChargedCandPt;
410  aTauPFEssential.etaAtEcalEntranceLeadChargedCand_ = leadChargedCandEtaAtEcalEntrance;
411  if (sumEnergy != 0.) {
412  aTauPFEssential.phiAtEcalEntrance_ = sumPhiTimesEnergy/sumEnergy;
413  aTauPFEssential.etaAtEcalEntrance_ = sumEtaTimesEnergy/sumEnergy;
414  }
415  else {
416  aTauPFEssential.phiAtEcalEntrance_ = -99.;
417  aTauPFEssential.etaAtEcalEntrance_ = -99.;
418  }
419  float leadingTrackNormChi2 = 0;
420  float ecalEnergyLeadChargedHadrCand = -99.;
421  float hcalEnergyLeadChargedHadrCand = -99.;
422  float emFraction = -1.;
423  float myHCALenergy = 0.;
424  float myECALenergy = 0.;
425  const reco::PFCandidatePtr& leadingPFCharged = pfTauRef->leadPFChargedHadrCand();
426  if(leadingPFCharged.isNonnull()) {
427  ecalEnergyLeadChargedHadrCand = leadingPFCharged->ecalEnergy();
428  hcalEnergyLeadChargedHadrCand = leadingPFCharged->hcalEnergy();
429  reco::TrackRef trackRef = leadingPFCharged->trackRef();
430  if( trackRef.isNonnull() ) {
431  leadingTrackNormChi2 = trackRef->normalizedChi2();
432  for( std::vector<reco::PFCandidatePtr>::const_iterator tauIt = pfTauRef->isolationPFCands().begin(); tauIt!=pfTauRef->isolationPFCands().end(); ++tauIt ){
433  myHCALenergy += (*tauIt)->hcalEnergy();
434  myECALenergy += (*tauIt)->ecalEnergy();
435  }
436  for( std::vector<reco::PFCandidatePtr>::const_iterator tauIt = pfTauRef->signalPFCands().begin(); tauIt!=pfTauRef->signalPFCands().end(); ++tauIt ){
437  myHCALenergy += (*tauIt)->hcalEnergy();
438  myECALenergy += (*tauIt)->ecalEnergy();
439  }
440  if( myHCALenergy + myECALenergy != 0. ) {
441  emFraction = myECALenergy/( myHCALenergy + myECALenergy);
442  }
443  }
444  }
445  aTauPFEssential.emFraction_ = emFraction;
446  aTauPFEssential.leadingTrackNormChi2_ = leadingTrackNormChi2;
447  aTauPFEssential.ecalEnergyLeadChargedHadrCand_ = ecalEnergyLeadChargedHadrCand;
448  aTauPFEssential.hcalEnergyLeadChargedHadrCand_ = hcalEnergyLeadChargedHadrCand;
449  // extraction of tau lifetime information
450  if( !tauTransverseImpactParameterSrc_.label().empty() ) {
451  edm::Handle<PFTauTIPAssociationByRef> tauLifetimeInfos;
452  iEvent.getByToken(tauTransverseImpactParameterToken_, tauLifetimeInfos);
453  const reco::PFTauTransverseImpactParameter& tauLifetimeInfo = *(*tauLifetimeInfos)[pfTauRef];
454  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
455  aTauPFEssential.dxy_PCA_ = tauLifetimeInfo.dxy_PCA();
456  aTauPFEssential.dxy_ = tauLifetimeInfo.dxy();
457  aTauPFEssential.dxy_error_ = tauLifetimeInfo.dxy_error();
458  aTauPFEssential.hasSV_ = tauLifetimeInfo.hasSecondaryVertex();
459  aTauPFEssential.flightLength_ = tauLifetimeInfo.flightLength();
460  aTauPFEssential.flightLengthSig_ = tauLifetimeInfo.flightLengthSig();
461  aTauPFEssential.ip3d_ = tauLifetimeInfo.ip3d();
462  aTauPFEssential.ip3d_error_ = tauLifetimeInfo.ip3d_error();
463  }
464  }
465 
466  // Isolation
467  if (isolator_.enabled()) {
469  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
470  // better to loop backwards, so the vector is resized less times
471  for ( IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
472  ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
473  aTau.setIsolation(it->first, it->second);
474  }
475  }
476 
477  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
478  aTau.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[tausRef]);
479  }
480 
481  if (efficiencyLoader_.enabled()) {
482  efficiencyLoader_.setEfficiencies( aTau, tausRef );
483  }
484 
485  if (resolutionLoader_.enabled()) {
487  }
488 
489  if ( useUserData_ ) {
490  userDataHelper_.add( aTau, iEvent, iSetup );
491  }
492 
493  patTaus->push_back(aTau);
494  }
495 
496  // sort taus in pT
497  std::sort(patTaus->begin(), patTaus->end(), pTTauComparator_);
498 
499  // put genEvt object in Event
500  iEvent.put(std::move(patTaus));
501 
502  // clean up
504 }
505 
506 template <typename TauCollectionType, typename TauDiscrType>
507 float PATTauProducer::getTauIdDiscriminator(const edm::Handle<TauCollectionType>& tauCollection, size_t tauIdx, const edm::Handle<TauDiscrType>& tauIdDiscr)
508 {
509  edm::Ref<TauCollectionType> tauRef(tauCollection, tauIdx);
510  return (*tauIdDiscr)[tauRef];
511 }
512 
513 // ParameterSet description for module
515 {
517  iDesc.setComment("PAT tau producer module");
518 
519  // input source
520  iDesc.add<edm::InputTag>("tauSource", edm::InputTag())->setComment("input collection");
521 
522  // embedding
523  iDesc.add<bool>("embedIsolationTracks", false)->setComment("embed external isolation tracks");
524  iDesc.add<bool>("embedLeadTrack", false)->setComment("embed external leading track");
525  iDesc.add<bool>("embedLeadTracks", false)->setComment("embed external signal tracks");
526 
527  // MC matching configurables
528  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
529  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
530  std::vector<edm::InputTag> emptySourceVector;
531  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
532  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
533  )->setComment("input with MC match information");
534 
535  // MC jet matching variables
536  iDesc.add<bool>("addGenJetMatch", true)->setComment("add MC jet matching");
537  iDesc.add<bool>("embedGenJetMatch", false)->setComment("embed MC jet matched jet information");
538  iDesc.add<edm::InputTag>("genJetMatch", edm::InputTag("tauGenJetMatch"));
539 
540 
542 
543  // tau ID configurables
544  iDesc.add<bool>("addTauID", true)->setComment("add tau ID variables");
545  edm::ParameterSetDescription tauIDSourcesPSet;
546  tauIDSourcesPSet.setAllowAnything();
547  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("tauIDSource", edm::InputTag(), true) xor
548  edm::ParameterDescription<edm::ParameterSetDescription>("tauIDSources", tauIDSourcesPSet, true)
549  )->setComment("input with tau ID variables");
550  // (Dis)allow to skip missing tauId sources
551  iDesc.add<bool>("skipMissingTauID", false)->setComment("allow to skip a tau ID variable when not present in the event");
552 
553  // IsoDeposit configurables
554  edm::ParameterSetDescription isoDepositsPSet;
555  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
556  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
557  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
558  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
559  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadron");
560  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadron");
561  isoDepositsPSet.addOptional<edm::InputTag>("pfGamma");
562  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
563  iDesc.addOptional("isoDeposits", isoDepositsPSet);
564 
565  // Efficiency configurables
566  edm::ParameterSetDescription efficienciesPSet;
567  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
568  iDesc.add("efficiencies", efficienciesPSet);
569  iDesc.add<bool>("addEfficiencies", false);
570 
571  // Check to see if the user wants to add user data
572  edm::ParameterSetDescription userDataPSet;
574  iDesc.addOptional("userData", userDataPSet);
575 
576  edm::ParameterSetDescription isolationPSet;
577  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
578  iDesc.add("userIsolation", isolationPSet);
579 
580 }
581 
583 
585 
586 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
~PATTauProducer() override
bool isAvailable() const
Definition: Ref.h:577
T getParameter(std::string const &) const
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:137
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
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:185
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
void embedIsolationPFCands()
method to store the isolation candidates internally
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
void embedIsolationPFGammaCands()
method to store the isolation gamma candidates internally
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:384
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
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
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:64
const std::string names[nVars_]
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)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:193
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:50
void setComment(std::string const &value)
void embedSignalPFCands()
method to store the signal candidates internally
int iEvent
Definition: GenABIO.cc:230
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:621
edm::EDGetTokenT< reco::CaloTauCollection > caloTauToken_
pat::PATUserDataHelper< pat::Tau > userDataHelper_
genJetMatch
switch on/off embedding of matched genJet&#39;s
bool embedSignalPFNeutralHadrCands_
std::vector< pat::tau::TauPFEssential > pfEssential_
Definition: Tau.h:533
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
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
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_
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
void addJECFactors(const TauJetCorrFactors &jec)
add more sets of energy correction factors
Definition: Tau.h:449
PATTauProducer(const edm::ParameterSet &iConfig)
HLT enums.
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:157
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()