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  for ( size_t i = 0; i < tauIDSrcs_.size(); ++i ) {
313  if ( typeid(*tausRef) == typeid(reco::PFTau) ) {
314  //std::cout << "filling PFTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
315  edm::Handle<reco::PFTauCollection> pfTauCollection;
316  iEvent.getByToken(pfTauToken_, pfTauCollection);
317 
319  iEvent.getByToken(pfTauIDTokens_[i], pfTauIdDiscr);
320 
321  if(skipMissingTauID_ && !pfTauIdDiscr.isValid()){
322  if(!missingDiscriminators.empty()){
323  missingDiscriminators+=", ";
324  }
325  missingDiscriminators+=tauIDSrcs_[i].first;
326  continue;
327  }
328  ids[i].first = tauIDSrcs_[i].first;
329  ids[i].second = getTauIdDiscriminator(pfTauCollection, idx, pfTauIdDiscr);
330  } else if ( typeid(*tausRef) == typeid(reco::CaloTau) ) {
331  //std::cout << "filling CaloTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
332  edm::Handle<reco::CaloTauCollection> caloTauCollection;
333  iEvent.getByToken(caloTauToken_, caloTauCollection);
334 
336  iEvent.getByToken(caloTauIDTokens_[i], caloTauIdDiscr);
337 
338  if(skipMissingTauID_ && !caloTauIdDiscr.isValid()){
339  if(!missingDiscriminators.empty()){
340  missingDiscriminators+=", ";
341  }
342  missingDiscriminators+=tauIDSrcs_[i].first;
343  continue;
344  }
345  ids[i].first = tauIDSrcs_[i].first;
346  ids[i].second = getTauIdDiscriminator(caloTauCollection, idx, caloTauIdDiscr);
347  } else {
348  throw cms::Exception("Type Mismatch") <<
349  "PATTauProducer: unsupported datatype '" << typeid(*tausRef).name() << "' for tauSource\n";
350  }
351  }
352  if(!missingDiscriminators.empty() && firstOccurence_){
353  edm::LogWarning("DataSource") << "The following tau discriminators have not been found in the event:\n"
354  << missingDiscriminators <<"\n"
355  << "They will not be embedded into the pat::Tau object.\n"
356  << "Note: this message will be printed only at first occurence.";
357  firstOccurence_=false;
358  }
359  aTau.setTauIDs(ids);
360  }
361 
362  // extraction of reconstructed tau decay mode
363  // (only available for PFTaus)
364  if ( aTau.isPFTau() ) {
366  iEvent.getByToken(pfTauToken_, pfTaus);
367  reco::PFTauRef pfTauRef(pfTaus, idx);
368 
369  aTau.setDecayMode(pfTauRef->decayMode());
370  }
371 
372  // extraction of variables needed to rerun MVA isolation and anti-electron discriminator on MiniAOD
373  if( aTau.isPFTau() ) {
375  iEvent.getByToken(pfTauToken_, pfTaus);
376  reco::PFTauRef pfTauRef(pfTaus, idx);
377  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
378  float ecalEnergy = 0;
379  float hcalEnergy = 0;
380  float sumPhiTimesEnergy = 0.;
381  float sumEtaTimesEnergy = 0.;
382  float sumEnergy = 0.;
383  float leadChargedCandPt = -99;
384  float leadChargedCandEtaAtEcalEntrance = -99;
385  const std::vector<reco::PFCandidatePtr>& signalCands = pfTauRef->signalPFCands();
386  for(std::vector<reco::PFCandidatePtr>::const_iterator it = signalCands.begin(); it != signalCands.end(); ++it) {
387  const reco::PFCandidatePtr& icand = *it;
388  ecalEnergy += icand->ecalEnergy();
389  hcalEnergy += icand->hcalEnergy();
390  sumPhiTimesEnergy += icand->positionAtECALEntrance().phi()*icand->energy();
391  sumEtaTimesEnergy += icand->positionAtECALEntrance().eta()*icand->energy();
392  sumEnergy += icand->energy();
393  const reco::Track* track = nullptr;
394  if ( icand->trackRef().isNonnull() ) track = icand->trackRef().get();
395  else if ( icand->muonRef().isNonnull() && icand->muonRef()->innerTrack().isNonnull() ) track = icand->muonRef()->innerTrack().get();
396  else if ( icand->muonRef().isNonnull() && icand->muonRef()->globalTrack().isNonnull() ) track = icand->muonRef()->globalTrack().get();
397  else if ( icand->muonRef().isNonnull() && icand->muonRef()->outerTrack().isNonnull() ) track = icand->muonRef()->outerTrack().get();
398  else if ( icand->gsfTrackRef().isNonnull() ) track = icand->gsfTrackRef().get();
399  if( track ) {
400  if( track->pt() > leadChargedCandPt ) {
401  leadChargedCandEtaAtEcalEntrance = icand->positionAtECALEntrance().eta();
402  leadChargedCandPt = track->pt();
403  }
404  }
405  }
406  aTauPFEssential.ecalEnergy_ = ecalEnergy;
407  aTauPFEssential.hcalEnergy_ = hcalEnergy;
408  aTauPFEssential.ptLeadChargedCand_ = leadChargedCandPt;
409  aTauPFEssential.etaAtEcalEntranceLeadChargedCand_ = leadChargedCandEtaAtEcalEntrance;
410  if (sumEnergy != 0.) {
411  aTauPFEssential.phiAtEcalEntrance_ = sumPhiTimesEnergy/sumEnergy;
412  aTauPFEssential.etaAtEcalEntrance_ = sumEtaTimesEnergy/sumEnergy;
413  }
414  else {
415  aTauPFEssential.phiAtEcalEntrance_ = -99.;
416  aTauPFEssential.etaAtEcalEntrance_ = -99.;
417  }
418  float leadingTrackNormChi2 = 0;
419  float ecalEnergyLeadChargedHadrCand = -99.;
420  float hcalEnergyLeadChargedHadrCand = -99.;
421  float emFraction = -1.;
422  float myHCALenergy = 0.;
423  float myECALenergy = 0.;
424  const reco::PFCandidatePtr& leadingPFCharged = pfTauRef->leadPFChargedHadrCand();
425  if(leadingPFCharged.isNonnull()) {
426  ecalEnergyLeadChargedHadrCand = leadingPFCharged->ecalEnergy();
427  hcalEnergyLeadChargedHadrCand = leadingPFCharged->hcalEnergy();
428  reco::TrackRef trackRef = leadingPFCharged->trackRef();
429  if( trackRef.isNonnull() ) {
430  leadingTrackNormChi2 = trackRef->normalizedChi2();
431  for( std::vector<reco::PFCandidatePtr>::const_iterator tauIt = pfTauRef->isolationPFCands().begin(); tauIt!=pfTauRef->isolationPFCands().end(); ++tauIt ){
432  myHCALenergy += (*tauIt)->hcalEnergy();
433  myECALenergy += (*tauIt)->ecalEnergy();
434  }
435  for( std::vector<reco::PFCandidatePtr>::const_iterator tauIt = pfTauRef->signalPFCands().begin(); tauIt!=pfTauRef->signalPFCands().end(); ++tauIt ){
436  myHCALenergy += (*tauIt)->hcalEnergy();
437  myECALenergy += (*tauIt)->ecalEnergy();
438  }
439  if( myHCALenergy + myECALenergy != 0. ) {
440  emFraction = myECALenergy/( myHCALenergy + myECALenergy);
441  }
442  }
443  }
444  aTauPFEssential.emFraction_ = emFraction;
445  aTauPFEssential.leadingTrackNormChi2_ = leadingTrackNormChi2;
446  aTauPFEssential.ecalEnergyLeadChargedHadrCand_ = ecalEnergyLeadChargedHadrCand;
447  aTauPFEssential.hcalEnergyLeadChargedHadrCand_ = hcalEnergyLeadChargedHadrCand;
448  // extraction of tau lifetime information
450  edm::Handle<PFTauTIPAssociationByRef> tauLifetimeInfos;
451  iEvent.getByToken(tauTransverseImpactParameterToken_, tauLifetimeInfos);
452  const reco::PFTauTransverseImpactParameter& tauLifetimeInfo = *(*tauLifetimeInfos)[pfTauRef];
453  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
454  aTauPFEssential.dxy_PCA_ = tauLifetimeInfo.dxy_PCA();
455  aTauPFEssential.dxy_ = tauLifetimeInfo.dxy();
456  aTauPFEssential.dxy_error_ = tauLifetimeInfo.dxy_error();
457  aTauPFEssential.hasSV_ = tauLifetimeInfo.hasSecondaryVertex();
458  aTauPFEssential.flightLength_ = tauLifetimeInfo.flightLength();
459  aTauPFEssential.flightLengthSig_ = tauLifetimeInfo.flightLengthSig();
460  aTauPFEssential.ip3d_ = tauLifetimeInfo.ip3d();
461  aTauPFEssential.ip3d_error_ = tauLifetimeInfo.ip3d_error();
462  }
463  }
464 
465  // Isolation
466  if (isolator_.enabled()) {
468  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
469  // better to loop backwards, so the vector is resized less times
470  for ( IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
471  ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
472  aTau.setIsolation(it->first, it->second);
473  }
474  }
475 
476  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
477  aTau.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[tausRef]);
478  }
479 
480  if (efficiencyLoader_.enabled()) {
481  efficiencyLoader_.setEfficiencies( aTau, tausRef );
482  }
483 
484  if (resolutionLoader_.enabled()) {
486  }
487 
488  if ( useUserData_ ) {
489  userDataHelper_.add( aTau, iEvent, iSetup );
490  }
491 
492  patTaus->push_back(aTau);
493  }
494 
495  // sort taus in pT
496  std::sort(patTaus->begin(), patTaus->end(), pTTauComparator_);
497 
498  // put genEvt object in Event
499  iEvent.put(std::move(patTaus));
500 
501  // clean up
503 }
504 
505 template <typename TauCollectionType, typename TauDiscrType>
506 float PATTauProducer::getTauIdDiscriminator(const edm::Handle<TauCollectionType>& tauCollection, size_t tauIdx, const edm::Handle<TauDiscrType>& tauIdDiscr)
507 {
508  edm::Ref<TauCollectionType> tauRef(tauCollection, tauIdx);
509  return (*tauIdDiscr)[tauRef];
510 }
511 
512 // ParameterSet description for module
514 {
516  iDesc.setComment("PAT tau producer module");
517 
518  // input source
519  iDesc.add<edm::InputTag>("tauSource", edm::InputTag())->setComment("input collection");
520 
521  // embedding
522  iDesc.add<bool>("embedIsolationTracks", false)->setComment("embed external isolation tracks");
523  iDesc.add<bool>("embedLeadTrack", false)->setComment("embed external leading track");
524  iDesc.add<bool>("embedLeadTracks", false)->setComment("embed external signal tracks");
525 
526  // MC matching configurables
527  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
528  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
529  std::vector<edm::InputTag> emptySourceVector;
530  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
531  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
532  )->setComment("input with MC match information");
533 
534  // MC jet matching variables
535  iDesc.add<bool>("addGenJetMatch", true)->setComment("add MC jet matching");
536  iDesc.add<bool>("embedGenJetMatch", false)->setComment("embed MC jet matched jet information");
537  iDesc.add<edm::InputTag>("genJetMatch", edm::InputTag("tauGenJetMatch"));
538 
539 
541 
542  // tau ID configurables
543  iDesc.add<bool>("addTauID", true)->setComment("add tau ID variables");
544  edm::ParameterSetDescription tauIDSourcesPSet;
545  tauIDSourcesPSet.setAllowAnything();
546  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("tauIDSource", edm::InputTag(), true) xor
547  edm::ParameterDescription<edm::ParameterSetDescription>("tauIDSources", tauIDSourcesPSet, true)
548  )->setComment("input with tau ID variables");
549  // (Dis)allow to skip missing tauId sources
550  iDesc.add<bool>("skipMissingTauID", false)->setComment("allow to skip a tau ID variable when not present in the event");
551 
552  // IsoDeposit configurables
553  edm::ParameterSetDescription isoDepositsPSet;
554  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
555  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
556  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
557  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
558  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadron");
559  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadron");
560  isoDepositsPSet.addOptional<edm::InputTag>("pfGamma");
561  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
562  iDesc.addOptional("isoDeposits", isoDepositsPSet);
563 
564  // Efficiency configurables
565  edm::ParameterSetDescription efficienciesPSet;
566  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
567  iDesc.add("efficiencies", efficienciesPSet);
568  iDesc.add<bool>("addEfficiencies", false);
569 
570  // Check to see if the user wants to add user data
571  edm::ParameterSetDescription userDataPSet;
573  iDesc.addOptional("userData", userDataPSet);
574 
575  edm::ParameterSetDescription isolationPSet;
576  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
577  iDesc.add("userIsolation", isolationPSet);
578 
579 }
580 
582 
584 
585 
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:186
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:194
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:510
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()