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