CMS 3D CMS Logo

HLTTauRefProducer.cc
Go to the documentation of this file.
2 #include "TLorentzVector.h"
3 // TAU includes
7 // ELECTRON includes
14 // MUON includes
17 #include "TLorentzVector.h"
19 //CaloTower includes
23 #include "Math/GenVector/VectorUtil.h"
24 
25 using namespace edm;
26 using namespace reco;
27 using namespace std;
28 
30  //One Parameter Set per Collection
31  {
32  auto const& pfTau = iConfig.getUntrackedParameter<edm::ParameterSet>("PFTaus");
33  PFTaus_ = consumes<reco::PFTauCollection>(pfTau.getUntrackedParameter<InputTag>("PFTauProducer"));
34  auto discs = pfTau.getUntrackedParameter<vector<InputTag>>("PFTauDiscriminators");
35  auto discConts = pfTau.getUntrackedParameter<vector<InputTag>>("PFTauDiscriminatorContainers");
36  PFTauDisContWPs_ = pfTau.getUntrackedParameter<vector<std::string>>("PFTauDiscriminatorContainerWPs");
37  if (discConts.size() != PFTauDisContWPs_.size())
38  throw cms::Exception("Configuration") << "HLTTauRefProducer: Input parameters PFTauDiscriminatorContainers and "
39  "PFTauDiscriminatorContainerWPs must have the same number of entries!\n";
40  for (auto const& tag : discs) {
41  PFTauDis_.push_back(consumes<reco::PFTauDiscriminator>(tag));
42  }
43  for (auto const& tag : discConts) {
44  PFTauDisCont_.push_back(consumes<reco::TauDiscriminatorContainer>(tag));
45  }
46  doPFTaus_ = pfTau.getUntrackedParameter<bool>("doPFTaus", false);
47  ptMinPFTau_ = pfTau.getUntrackedParameter<double>("ptMin", 15.);
48  etaMinPFTau_ = pfTau.getUntrackedParameter<double>("etaMin", -2.5);
49  etaMaxPFTau_ = pfTau.getUntrackedParameter<double>("etaMax", 2.5);
50  phiMinPFTau_ = pfTau.getUntrackedParameter<double>("phiMin", -3.15);
51  phiMaxPFTau_ = pfTau.getUntrackedParameter<double>("phiMax", 3.15);
52  }
53 
54  {
55  auto const& electrons = iConfig.getUntrackedParameter<edm::ParameterSet>("Electrons");
56  Electrons_ = consumes<reco::GsfElectronCollection>(electrons.getUntrackedParameter<InputTag>("ElectronCollection"));
57  doElectrons_ = electrons.getUntrackedParameter<bool>("doElectrons", false);
58  e_ctfTrackCollectionSrc_ = electrons.getUntrackedParameter<InputTag>("TrackCollection");
59  e_ctfTrackCollection_ = consumes<reco::TrackCollection>(e_ctfTrackCollectionSrc_);
60  ptMinElectron_ = electrons.getUntrackedParameter<double>("ptMin", 15.);
61  e_doTrackIso_ = electrons.getUntrackedParameter<bool>("doTrackIso", false);
62  e_trackMinPt_ = electrons.getUntrackedParameter<double>("ptMinTrack", 1.5);
63  e_lipCut_ = electrons.getUntrackedParameter<double>("lipMinTrack", 1.5);
64  e_minIsoDR_ = electrons.getUntrackedParameter<double>("InnerConeDR", 0.02);
65  e_maxIsoDR_ = electrons.getUntrackedParameter<double>("OuterConeDR", 0.6);
66  e_isoMaxSumPt_ = electrons.getUntrackedParameter<double>("MaxIsoVar", 0.02);
67  }
68 
69  {
70  auto const& muons = iConfig.getUntrackedParameter<edm::ParameterSet>("Muons");
71  Muons_ = consumes<reco::MuonCollection>(muons.getUntrackedParameter<InputTag>("MuonCollection"));
72  doMuons_ = muons.getUntrackedParameter<bool>("doMuons", false);
73  ptMinMuon_ = muons.getUntrackedParameter<double>("ptMin", 15.);
74  }
75 
76  {
77  auto const& jets = iConfig.getUntrackedParameter<edm::ParameterSet>("Jets");
78  Jets_ = consumes<reco::CaloJetCollection>(jets.getUntrackedParameter<InputTag>("JetCollection"));
79  doJets_ = jets.getUntrackedParameter<bool>("doJets");
80  ptMinJet_ = jets.getUntrackedParameter<double>("etMin");
81  }
82 
83  {
84  auto const& towers = iConfig.getUntrackedParameter<edm::ParameterSet>("Towers");
85  Towers_ = consumes<CaloTowerCollection>(towers.getUntrackedParameter<InputTag>("TowerCollection"));
86  doTowers_ = towers.getUntrackedParameter<bool>("doTowers");
87  ptMinTower_ = towers.getUntrackedParameter<double>("etMin");
88  towerIsol_ = towers.getUntrackedParameter<double>("towerIsolation");
89  }
90 
91  {
92  auto const& photons = iConfig.getUntrackedParameter<edm::ParameterSet>("Photons");
93  Photons_ = consumes<reco::PhotonCollection>(photons.getUntrackedParameter<InputTag>("PhotonCollection"));
94  doPhotons_ = photons.getUntrackedParameter<bool>("doPhotons");
95  ptMinPhoton_ = photons.getUntrackedParameter<double>("etMin");
96  photonEcalIso_ = photons.getUntrackedParameter<double>("ECALIso");
97  }
98 
99  {
100  auto const& met = iConfig.getUntrackedParameter<edm::ParameterSet>("MET");
101  MET_ = consumes<reco::CaloMETCollection>(met.getUntrackedParameter<InputTag>("METCollection"));
102  doMET_ = met.getUntrackedParameter<bool>("doMET", false);
103  ptMinMET_ = met.getUntrackedParameter<double>("ptMin", 15.);
104  }
105 
106  etaMin_ = iConfig.getUntrackedParameter<double>("EtaMin", -2.5);
107  etaMax_ = iConfig.getUntrackedParameter<double>("EtaMax", 2.5);
108  phiMin_ = iConfig.getUntrackedParameter<double>("PhiMin", -3.15);
109  phiMax_ = iConfig.getUntrackedParameter<double>("PhiMax", 3.15);
110 
111  //recoCollections
112  produces<LorentzVectorCollection>("PFTaus");
113  produces<LorentzVectorCollection>("Electrons");
114  produces<LorentzVectorCollection>("Muons");
115  produces<LorentzVectorCollection>("Jets");
116  produces<LorentzVectorCollection>("Photons");
117  produces<LorentzVectorCollection>("Towers");
118  produces<LorentzVectorCollection>("MET");
119 }
120 
122  if (doPFTaus_)
123  doPFTaus(iID, iEvent);
124  if (doElectrons_)
126  if (doMuons_)
127  doMuons(iEvent);
128  if (doJets_)
129  doJets(iEvent);
130  if (doPhotons_)
131  doPhotons(iEvent);
132  if (doTowers_)
133  doTowers(iEvent);
134  if (doMET_)
135  doMET(iEvent);
136 }
137 
139  auto product_PFTaus = make_unique<LorentzVectorCollection>();
140 
142  if (iEvent.getByToken(PFTaus_, pftaus)) {
143  // Retrieve ID container indices if config history changes, in particular for the first event.
144  if (streamCache(iID)->first != iEvent.processHistoryID()) {
145  streamCache(iID)->first = iEvent.processHistoryID();
146  streamCache(iID)->second.resize(PFTauDisContWPs_.size());
147  for (size_t i = 0; i < PFTauDisCont_.size(); ++i) {
148  auto const aHandle = iEvent.getHandle(PFTauDisCont_[i]);
149  auto const aProv = aHandle.provenance();
150  if (aProv == nullptr)
151  aHandle.whyFailed()->raise();
152  const auto& psetsFromProvenance = edm::parameterSet(*aProv, iEvent.processHistory());
153  if (psetsFromProvenance.exists("workingPoints")) {
154  auto const idlist = psetsFromProvenance.getParameter<std::vector<std::string>>("workingPoints");
155  bool found = false;
156  for (size_t j = 0; j < idlist.size(); ++j) {
157  if (PFTauDisContWPs_[i] == idlist[j]) {
158  found = true;
159  streamCache(iID)->second[i] = j;
160  }
161  }
162  if (!found)
163  throw cms::Exception("Configuration")
164  << "HLTTauRefProducer: Requested working point '" << PFTauDisContWPs_[i] << "' not found!\n";
165  } else if (psetsFromProvenance.exists("IDWPdefinitions")) {
166  auto const idlist = psetsFromProvenance.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
167  bool found = false;
168  for (size_t j = 0; j < idlist.size(); ++j) {
169  if (PFTauDisContWPs_[i] == idlist[j].getParameter<std::string>("IDname")) {
170  found = true;
171  streamCache(iID)->second[i] = j;
172  }
173  }
174  if (!found)
175  throw cms::Exception("Configuration")
176  << "HLTTauRefProducer: Requested working point '" << PFTauDisContWPs_[i] << "' not found!\n";
177  } else
178  throw cms::Exception("Configuration")
179  << "HLTTauRefProducer: No suitable ID list found in provenace config!\n";
180  }
181  }
182  for (unsigned int i = 0; i < pftaus->size(); ++i) {
183  auto const& pftau = (*pftaus)[i];
184  if (pftau.pt() > ptMinPFTau_ && pftau.eta() > etaMinPFTau_ && pftau.eta() < etaMaxPFTau_ &&
185  pftau.phi() > phiMinPFTau_ && pftau.phi() < phiMaxPFTau_) {
186  reco::PFTauRef thePFTau{pftaus, i};
187  bool passAll{true};
188  for (auto const& token : PFTauDis_) {
190  if (iEvent.getByToken(token, pftaudis)) {
191  if ((*pftaudis)[thePFTau] < 0.5) {
192  passAll = false;
193  break;
194  }
195  } else {
196  passAll = false;
197  break;
198  }
199  }
200  int idx = 0;
201  for (auto const& token : PFTauDisCont_) {
203  if (iEvent.getByToken(token, pftaudis)) {
204  //WP vector not filled if prediscriminator in RecoTauDiscriminator failed.
205  if ((*pftaudis)[thePFTau].workingPoints.empty() ||
206  !(*pftaudis)[thePFTau].workingPoints.at(streamCache(iID)->second[idx])) {
207  passAll = false;
208  break;
209  }
210  } else {
211  passAll = false;
212  break;
213  }
214  idx++;
215  }
216  if (passAll) {
217  product_PFTaus->emplace_back(pftau.px(), pftau.py(), pftau.pz(), pftau.energy());
218  }
219  }
220  }
221  }
222  iEvent.put(move(product_PFTaus), "PFTaus");
223 }
224 
226  auto product_Electrons = make_unique<LorentzVectorCollection>();
227 
229  if (!iEvent.getByToken(e_ctfTrackCollection_, pCtfTracks)) {
230  edm::LogInfo("") << "Error! Can't get " << e_ctfTrackCollectionSrc_.label() << " by label. ";
231  iEvent.put(move(product_Electrons), "Electrons");
232  return;
233  }
234 
236  if (iEvent.getByToken(Electrons_, electrons)) {
237  for (size_t i = 0; i < electrons->size(); ++i) {
239  auto const& electron = (*electrons)[i];
240  if (electron.pt() > ptMinElectron_ && fabs(electron.eta()) < etaMax_) {
241  if (e_doTrackIso_) {
242  double sum_of_pt_ele{};
243  for (auto const& tr : *pCtfTracks) {
244  double const lip{electron.gsfTrack()->dz() - tr.dz()};
245  if (tr.pt() > e_trackMinPt_ && fabs(lip) < e_lipCut_) {
246  double dphi{fabs(tr.phi() - electron.trackMomentumAtVtx().phi())};
247  if (dphi > acos(-1.)) {
248  dphi = 2 * acos(-1.) - dphi;
249  }
250  double const deta{fabs(tr.eta() - electron.trackMomentumAtVtx().eta())};
251  double const dr_ctf_ele{sqrt(deta * deta + dphi * dphi)};
252  if ((dr_ctf_ele > e_minIsoDR_) && (dr_ctf_ele < e_maxIsoDR_)) {
253  double const cft_pt_2{tr.pt() * tr.pt()};
254  sum_of_pt_ele += cft_pt_2;
255  }
256  }
257  }
258  double const isolation_value_ele{sum_of_pt_ele /
259  (electron.trackMomentumAtVtx().Rho() * electron.trackMomentumAtVtx().Rho())};
260  if (isolation_value_ele < e_isoMaxSumPt_) {
261  product_Electrons->emplace_back(electron.px(), electron.py(), electron.pz(), electron.energy());
262  }
263  } else {
264  product_Electrons->emplace_back(electron.px(), electron.py(), electron.pz(), electron.energy());
265  }
266  }
267  }
268  }
269  iEvent.put(move(product_Electrons), "Electrons");
270 }
271 
273  auto product_Muons = make_unique<LorentzVectorCollection>();
274 
276  if (iEvent.getByToken(Muons_, muons)) {
277  for (auto const& muon : *muons) {
278  if (muon.pt() > ptMinMuon_ && muon.eta() > etaMin_ && muon.eta() < etaMax_ && muon.phi() > phiMin_ &&
279  muon.phi() < phiMax_) {
280  product_Muons->emplace_back(muon.px(), muon.py(), muon.pz(), muon.energy());
281  }
282  }
283  }
284  iEvent.put(move(product_Muons), "Muons");
285 }
286 
288  auto product_Jets = make_unique<LorentzVectorCollection>();
289 
291  if (iEvent.getByToken(Jets_, jets)) {
292  for (auto const& jet : *jets) {
293  if (jet.et() > ptMinJet_ && jet.eta() > etaMin_ && jet.eta() < etaMax_ && jet.phi() > phiMin_ &&
294  jet.phi() < phiMax_) {
295  product_Jets->emplace_back(jet.px(), jet.py(), jet.pz(), jet.energy());
296  }
297  }
298  }
299  iEvent.put(move(product_Jets), "Jets");
300 }
301 
303  auto product_Towers = make_unique<LorentzVectorCollection>();
304 
306  if (iEvent.getByToken(Towers_, towers)) {
307  for (auto const& tower1 : *towers) {
308  if (tower1.pt() > ptMinTower_ && tower1.eta() > etaMin_ && tower1.eta() < etaMax_ && tower1.phi() > phiMin_ &&
309  tower1.phi() < phiMax_) {
310  //calculate isolation
311  double isolET{};
312  for (auto const& tower2 : *towers) {
313  if (ROOT::Math::VectorUtil::DeltaR(tower1.p4(), tower2.p4()) < 0.5) {
314  isolET += tower2.pt();
315  }
316  isolET -= tower1.pt();
317  }
318  if (isolET < towerIsol_) {
319  product_Towers->emplace_back(tower1.px(), tower1.py(), tower1.pz(), tower1.energy());
320  }
321  }
322  }
323  }
324  iEvent.put(move(product_Towers), "Towers");
325 }
326 
328  auto product_Gammas = make_unique<LorentzVectorCollection>();
329 
331  if (iEvent.getByToken(Photons_, photons)) {
332  for (auto const& photon : *photons) {
333  if (photon.ecalRecHitSumEtConeDR04() < photonEcalIso_ && photon.et() > ptMinPhoton_ && photon.eta() > etaMin_ &&
334  photon.eta() < etaMax_ && photon.phi() > phiMin_ && photon.phi() < phiMax_) {
335  product_Gammas->emplace_back(photon.px(), photon.py(), photon.pz(), photon.energy());
336  }
337  }
338  }
339  iEvent.put(move(product_Gammas), "Photons");
340 }
341 
343  auto product_MET = make_unique<LorentzVectorCollection>();
344 
346  if (iEvent.getByToken(MET_, met) && !met->empty()) {
347  auto const& metMom = met->front().p4();
348  product_MET->emplace_back(metMom.Px(), metMom.Py(), 0, metMom.Pt());
349  }
350  iEvent.put(move(product_MET), "MET");
351 }
edm::StreamID
Definition: StreamID.h:30
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
CaloJet.h
mps_fire.i
i
Definition: mps_fire.py:355
Muon.h
CaloTower.h
HLTTauRefProducer::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: HLTTauRefProducer.cc:121
PFTauDiscriminator.h
muon
Definition: MuonCocktails.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
HLTTauRefProducer::doElectrons
void doElectrons(edm::Event &) const
Definition: HLTTauRefProducer.cc:225
edm::LogInfo
Definition: MessageLogger.h:254
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
HLTTauDQMOffline_cfi.doMuons
doMuons
Definition: HLTTauDQMOffline_cfi.py:58
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLTTauRefProducer::doPhotons
void doPhotons(edm::Event &) const
Definition: HLTTauRefProducer.cc:327
HLTTauRefProducer::doTowers
void doTowers(edm::Event &) const
Definition: HLTTauRefProducer.cc:302
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
training_settings.idx
idx
Definition: training_settings.py:16
edm::Ref< PFTauCollection >
qcdUeDQM_cfi.lip
lip
Definition: qcdUeDQM_cfi.py:25
BTaggingMonitor_cfi.met
met
Definition: BTaggingMonitor_cfi.py:84
HLTTauRefProducer::HLTTauRefProducer
HLTTauRefProducer(const edm::ParameterSet &)
Definition: HLTTauRefProducer.cc:29
deltaR.h
HLTTauDQMOffline_cfi.doPhotons
doPhotons
Definition: HLTTauDQMOffline_cfi.py:64
Track.h
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
HLTTauRefProducer::doMuons
void doMuons(edm::Event &) const
Definition: HLTTauRefProducer.cc:272
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
metsig::electron
Definition: SignAlgoResolutions.h:48
CaloTowerDefs.h
GsfElectron.h
HLTTauDQMOffline_cfi.doTowers
doTowers
Definition: HLTTauDQMOffline_cfi.py:53
ElectronFwd.h
HLTTauDQMOffline_cfi.doPFTaus
doPFTaus
Definition: HLTTauDQMOffline_cfi.py:23
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:36
iEvent
int iEvent
Definition: GenABIO.cc:224
GsfTrack.h
TauDiscriminatorContainer.h
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
HLTTauDQMOffline_cfi.doElectrons
doElectrons
Definition: HLTTauDQMOffline_cfi.py:36
edm::EventSetup
Definition: EventSetup.h:57
HLTTauRefProducer::doJets
void doJets(edm::Event &) const
Definition: HLTTauRefProducer.cc:287
electronAnalyzer_cfi.DeltaR
DeltaR
Definition: electronAnalyzer_cfi.py:33
HLTTauRefProducer::doMET
void doMET(edm::Event &) const
Definition: HLTTauRefProducer.cc:342
CaloTowerCollection.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
HLT_2018_cff.towers
towers
Definition: HLT_2018_cff.py:35030
Electron.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HLTTauRefProducer::doPFTaus
void doPFTaus(edm::StreamID, edm::Event &) const
Definition: HLTTauRefProducer.cc:138
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
metsig::jet
Definition: SignAlgoResolutions.h:47
Exception
Definition: hltDiff.cc:246
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
PFTau.h
HLTTauDQMOffline_cfi.doJets
doJets
Definition: HLTTauDQMOffline_cfi.py:48
cms::Exception
Definition: Exception.h:70
HLTTauDQMOffline_cfi.doMET
doMET
Definition: HLTTauDQMOffline_cfi.py:71
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
HLTTauRefProducer.h
edm::InputTag
Definition: InputTag.h:15
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316