CMS 3D CMS Logo

BoostedTauSeedsProducer.cc
Go to the documentation of this file.
1 
2 /* =============================================================================
3  * Filename: BoostedTauSeedsProducer.cc
4  *
5  * Description: Take the two subjets found by CMSBoostedTauSeedingAlgorithm
6  * and add the data-formats for
7  * o seeding the reconstruction of hadronic taus (PFJets, collection of PFCandidates not within subjet)
8  * o computation of electron and muon isolation Pt-sums, excluding the particles in the other subjet (collection of PFCandidates within subjet, used to define "Vetos")
9  *
10  * Created: 10/22/2013 16:05:00
11  *
12  * Authors: Christian Veelken (LLR)
13  *
14  * =============================================================================
15  */
16 
24 
36 
37 #include <TMath.h>
38 
39 #include <string>
40 #include <iostream>
41 #include <iomanip>
42 
44 public:
47  void produce(edm::Event&, const edm::EventSetup&) override;
48 
49 private:
50  typedef edm::AssociationMap<edm::OneToMany<std::vector<reco::PFJet>, std::vector<reco::PFCandidate>, unsigned int> >
52 
54 
58 
60 };
61 
63  : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
64  srcSubjets_ = consumes<JetView>(cfg.getParameter<edm::InputTag>("subjetSrc"));
65  srcPFCandidates_ = consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("pfCandidateSrc"));
66 
67  verbosity_ = (cfg.exists("verbosity")) ? cfg.getParameter<int>("verbosity") : 0;
68 
69  produces<reco::PFJetCollection>();
70  produces<JetToPFCandidateAssociation>("pfCandAssocMapForIsolation");
71  //produces<JetToPFCandidateAssociation>("pfCandAssocMapForIsoDepositVetos");
72 }
73 
74 namespace {
75  typedef std::vector<std::unordered_set<uint32_t> > JetToConstitMap;
76 
77  reco::PFJet convertToPFJet(const reco::Jet& jet, const reco::Jet::Constituents& jetConstituents) {
78  // CV: code for filling pfJetSpecific objects taken from
79  // RecoParticleFlow/PFRootEvent/src/JetMaker.cc
80  double chargedHadronEnergy = 0.;
81  double neutralHadronEnergy = 0.;
82  double chargedEmEnergy = 0.;
83  double neutralEmEnergy = 0.;
84  double chargedMuEnergy = 0.;
85  int chargedMultiplicity = 0;
86  int neutralMultiplicity = 0;
87  int muonMultiplicity = 0;
88  for (auto const& jetConstituent : jetConstituents) {
89  const reco::PFCandidate* pfCandidate = dynamic_cast<const reco::PFCandidate*>(jetConstituent.get());
90  if (pfCandidate) {
91  switch (pfCandidate->particleId()) {
92  case reco::PFCandidate::h: // charged hadron
93  chargedHadronEnergy += pfCandidate->energy();
94  ++chargedMultiplicity;
95  break;
96  case reco::PFCandidate::e: // electron
97  chargedEmEnergy += pfCandidate->energy();
98  ++chargedMultiplicity;
99  break;
100  case reco::PFCandidate::mu: // muon
101  chargedMuEnergy += pfCandidate->energy();
102  ++chargedMultiplicity;
104  break;
105  case reco::PFCandidate::gamma: // photon
106  case reco::PFCandidate::egamma_HF: // electromagnetic in HF
107  neutralEmEnergy += pfCandidate->energy();
108  ++neutralMultiplicity;
109  break;
110  case reco::PFCandidate::h0: // neutral hadron
111  case reco::PFCandidate::h_HF: // hadron in HF
112  neutralHadronEnergy += pfCandidate->energy();
113  ++neutralMultiplicity;
114  break;
115  default:
116  edm::LogWarning("convertToPFJet")
117  << "PFCandidate: Pt = " << pfCandidate->pt() << ", eta = " << pfCandidate->eta()
118  << ", phi = " << pfCandidate->phi() << " has invalid particleID = " << pfCandidate->particleId()
119  << " !!" << std::endl;
120  break;
121  }
122  } else {
123  edm::LogWarning("convertToPFJet")
124  << "Jet constituent: Pt = " << jetConstituent->pt() << ", eta = " << jetConstituent->eta()
125  << ", phi = " << jetConstituent->phi() << " is not of type PFCandidate !!" << std::endl;
126  }
127  }
128  reco::PFJet::Specific pfJetSpecific;
129  pfJetSpecific.mChargedHadronEnergy = chargedHadronEnergy;
130  pfJetSpecific.mNeutralHadronEnergy = neutralHadronEnergy;
131  pfJetSpecific.mChargedEmEnergy = chargedEmEnergy;
132  pfJetSpecific.mChargedMuEnergy = chargedMuEnergy;
133  pfJetSpecific.mNeutralEmEnergy = neutralEmEnergy;
134  pfJetSpecific.mChargedMultiplicity = chargedMultiplicity;
135  pfJetSpecific.mNeutralMultiplicity = neutralMultiplicity;
136  pfJetSpecific.mMuonMultiplicity = muonMultiplicity;
137 
138  reco::PFJet pfJet(jet.p4(), jet.vertex(), pfJetSpecific, jetConstituents);
139  pfJet.setJetArea(jet.jetArea());
140 
141  return pfJet;
142  }
143 
144  void getJetConstituents(const reco::Jet& jet, reco::Jet::Constituents& jet_and_subjetConstituents) {
145  reco::Jet::Constituents jetConstituents = jet.getJetConstituents();
146  for (auto const& jetConstituent : jetConstituents) {
147  const reco::Jet* subjet = dynamic_cast<const reco::Jet*>(jetConstituent.get());
148  if (subjet) {
149  getJetConstituents(*subjet, jet_and_subjetConstituents);
150  } else {
151  jet_and_subjetConstituents.push_back(jetConstituent);
152  }
153  }
154  }
155 
156  std::vector<reco::PFCandidateRef> getPFCandidates_exclJetConstituents(
157  const reco::Jet& jet,
159  const JetToConstitMap::value_type& constitmap,
160  bool invert) {
161  auto const& collection_cand = (*pfCandidates);
162  std::vector<reco::PFCandidateRef> pfCandidates_exclJetConstituents;
163  size_t numPFCandidates = pfCandidates->size();
164  for (size_t pfCandidateIdx = 0; pfCandidateIdx < numPFCandidates; ++pfCandidateIdx) {
165  if (!(deltaR2(collection_cand[pfCandidateIdx], jet) < 1.0))
166  continue;
167  bool isJetConstituent = constitmap.count(pfCandidateIdx);
168  if (!(isJetConstituent ^ invert)) {
169  reco::PFCandidateRef pfCandidate(pfCandidates, pfCandidateIdx);
170  pfCandidates_exclJetConstituents.push_back(pfCandidate);
171  }
172  }
173  return pfCandidates_exclJetConstituents;
174  }
175 
176  void printJetConstituents(const std::string& label, const reco::Jet::Constituents& jetConstituents) {
177  std::cout << "#" << label << " = " << jetConstituents.size() << ":" << std::endl;
178  unsigned idx = 0;
179  for (auto const& jetConstituent : jetConstituents) {
180  std::cout << " jetConstituent #" << idx << ": Pt = " << (*jetConstituent).pt()
181  << ", eta = " << (*jetConstituent).eta() << ", phi = " << (*jetConstituent).phi() << std::endl;
182  ++idx;
183  }
184  }
185 } // namespace
186 
188  if (verbosity_ >= 1) {
189  std::cout << "<BoostedTauSeedsProducer::produce (moduleLabel = " << moduleLabel_ << ")>:" << std::endl;
190  }
191 
192  edm::Handle<JetView> subjets;
193  evt.getByToken(srcSubjets_, subjets);
194  if (verbosity_ >= 1) {
195  std::cout << "#subjets = " << subjets->size() << std::endl;
196  }
197  assert((subjets->size() % 2) == 0); // CV: ensure that subjets come in pairs
198 
201  if (verbosity_ >= 1) {
202  std::cout << "#pfCandidates = " << pfCandidates->size() << std::endl;
203  }
204 
205  auto selectedSubjets = std::make_unique<reco::PFJetCollection>();
207 
208  auto selectedSubjetPFCandidateAssociationForIsolation =
209  std::make_unique<JetToPFCandidateAssociation>(&evt.productGetter());
210  //auto selectedSubjetPFCandidateAssociationForIsoDepositVetos = std::make_unique<JetToPFCandidateAssociation>(&evt.productGetter());
211 
212  // cache for jet->pfcandidate
213  JetToConstitMap constitmap(subjets->size());
214 
215  // fill constituents map
216  const auto& thesubjets = *subjets;
217  for (unsigned i = 0; i < thesubjets.size(); ++i) {
218  for (unsigned j = 0; j < thesubjets[i].numberOfDaughters(); ++j) {
219  constitmap[i].emplace(thesubjets[i].daughterPtr(j).key());
220  }
221  }
222 
223  for (size_t idx = 0; idx < (subjets->size() / 2); ++idx) {
224  const reco::Jet* subjet1 = &subjets->at(2 * idx);
225  const reco::Jet* subjet2 = &subjets->at(2 * idx + 1);
226  assert(subjet1 && subjet2);
227  if (verbosity_ >= 1) {
228  std::cout << "processing jet #" << idx << ":" << std::endl;
229  std::cout << " subjet1: Pt = " << subjet1->pt() << ", eta = " << subjet1->eta() << ", phi = " << subjet1->phi()
230  << ", mass = " << subjet1->mass() << " (#constituents = " << subjet1->nConstituents()
231  << ", area = " << subjet1->jetArea() << ")" << std::endl;
232  std::cout << " subjet2: Pt = " << subjet2->pt() << ", eta = " << subjet2->eta() << ", phi = " << subjet2->phi()
233  << ", mass = " << subjet2->mass() << " (#constituents = " << subjet2->nConstituents()
234  << ", area = " << subjet2->jetArea() << ")" << std::endl;
235  }
236 
237  if (!(subjet1->nConstituents() >= 1 && subjet1->pt() > 1. && subjet2->nConstituents() >= 1 && subjet2->pt() > 1.))
238  continue; // CV: skip pathological cases
239 
240  // find PFCandidate constituents of each subjet
241  reco::Jet::Constituents subjetConstituents1;
242  getJetConstituents(*subjet1, subjetConstituents1);
243  reco::Jet::Constituents subjetConstituents2;
244  getJetConstituents(*subjet2, subjetConstituents2);
245  if (verbosity_ >= 1) {
246  printJetConstituents("subjetConstituents1", subjetConstituents1);
247  printJetConstituents("subjetConstituents2", subjetConstituents2);
248  }
249 
250  selectedSubjets->push_back(convertToPFJet(*subjet1, subjetConstituents1));
251  edm::Ref<reco::PFJetCollection> subjetRef1(selectedSubjetRefProd, selectedSubjets->size() - 1);
252  selectedSubjets->push_back(convertToPFJet(*subjet2, subjetConstituents2));
253  edm::Ref<reco::PFJetCollection> subjetRef2(selectedSubjetRefProd, selectedSubjets->size() - 1);
254 
255  // find all PFCandidates that are not constituents of the **other** subjet
256  std::vector<reco::PFCandidateRef> pfCandidatesNotInSubjet1 =
257  getPFCandidates_exclJetConstituents(*subjet1, pfCandidates, constitmap[2 * idx + 1], false);
258  std::vector<reco::PFCandidateRef> pfCandidatesNotInSubjet2 =
259  getPFCandidates_exclJetConstituents(*subjet2, pfCandidates, constitmap[2 * idx], false);
260  if (verbosity_ >= 1) {
261  std::cout << "#pfCandidatesNotInSubjet1 = " << pfCandidatesNotInSubjet1.size() << std::endl;
262  std::cout << "#pfCandidatesNotInSubjet2 = " << pfCandidatesNotInSubjet2.size() << std::endl;
263  }
264 
265  // build JetToPFCandidateAssociation
266  // (key = subjet, value = collection of PFCandidates that are not constituents of subjet)
267  for (auto const& pfCandidate : pfCandidatesNotInSubjet1) {
268  selectedSubjetPFCandidateAssociationForIsolation->insert(subjetRef1, pfCandidate);
269  }
270  for (auto const& pfCandidate : pfCandidatesNotInSubjet2) {
271  selectedSubjetPFCandidateAssociationForIsolation->insert(subjetRef2, pfCandidate);
272  }
273  }
274 
275  evt.put(std::move(selectedSubjets));
276  evt.put(std::move(selectedSubjetPFCandidateAssociationForIsolation), "pfCandAssocMapForIsolation");
277 }
278 
edm::RefProd
Definition: EDProductfwd.h:25
RefProd.h
BoostedTauSeedsProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: BoostedTauSeedsProducer.cc:187
edm::Event::getRefBeforePut
RefProd< PROD > getRefBeforePut()
Definition: Event.h:158
Handle.h
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
reco::PFJet::Specific::mNeutralEmEnergy
float mNeutralEmEnergy
Definition: PFJet.h:71
mps_fire.i
i
Definition: mps_fire.py:428
reco::Jet
Base class for all types of Jets.
Definition: Jet.h:20
MessageLogger.h
reco::Jet::Constituents
std::vector< Constituent > Constituents
Definition: Jet.h:23
reco::PFCandidate::e
Definition: PFCandidate.h:47
BoostedTauSeedsProducer::srcSubjets_
edm::EDGetTokenT< JetView > srcSubjets_
Definition: BoostedTauSeedsProducer.cc:56
PFCandidate.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
AssociationMap.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::Event::productGetter
EDProductGetter const & productGetter() const
Definition: Event.cc:105
PFJet.h
PFJetCollection.h
reco::PFCandidate::h
Definition: PFCandidate.h:46
reco::PFCandidate::h_HF
Definition: PFCandidate.h:51
cms::cuda::assert
assert(be >=bs)
EDProducer.h
Jet.h
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco::PFJet::Specific::mNeutralMultiplicity
int mNeutralMultiplicity
Definition: PFJet.h:73
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::Ref< PFCandidateCollection >
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
reco::Jet::setJetArea
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:101
reco::PFJet::Specific::mMuonMultiplicity
int mMuonMultiplicity
Definition: PFJet.h:63
BoostedTauSeedsProducer::srcPFCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidates_
Definition: BoostedTauSeedsProducer.cc:57
MakerMacros.h
reco::PFJet::Specific::mNeutralHadronEnergy
float mNeutralHadronEnergy
Definition: PFJet.h:52
BoostedTauSeedsProducer::~BoostedTauSeedsProducer
~BoostedTauSeedsProducer() override
Definition: BoostedTauSeedsProducer.cc:46
reco::PFJet::Specific::mChargedMultiplicity
int mChargedMultiplicity
Definition: PFJet.h:72
BoostedTauSeedsProducer
Definition: BoostedTauSeedsProducer.cc:43
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::PFCandidate::mu
Definition: PFCandidate.h:48
reco::Jet::nConstituents
virtual int nConstituents() const
Definition: Jet.h:65
reco::btau::muonMultiplicity
Definition: TaggingVariable.h:112
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
reco::PFJet::Specific::mChargedHadronEnergy
float mChargedHadronEnergy
Definition: PFJet.h:51
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::Jet::jetArea
virtual float jetArea() const
get jet area
Definition: Jet.h:103
edm::View::size
size_type size() const
BoostedTauSeedsProducer::BoostedTauSeedsProducer
BoostedTauSeedsProducer(const edm::ParameterSet &)
Definition: BoostedTauSeedsProducer.cc:62
BoostedTauSeedsProducer::moduleLabel_
std::string moduleLabel_
Definition: BoostedTauSeedsProducer.cc:53
edm::View
Definition: CaloClusterFwd.h:14
edm::View::at
const_reference at(size_type pos) const
edm::ParameterSet
Definition: ParameterSet.h:47
reco::LeafCandidate::mass
double mass() const final
mass
Definition: LeafCandidate.h:131
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
deltaR.h
reco::PFCandidate::particleId
virtual ParticleType particleId() const
Definition: PFCandidate.h:367
edm::AssociationMap
Definition: AssociationMap.h:48
reco::PFCandidate::egamma_HF
Definition: PFCandidate.h:52
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
reco::PFCandidate::gamma
Definition: PFCandidate.h:49
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
reco::PFJet::Specific::mChargedMuEnergy
float mChargedMuEnergy
Definition: PFJet.h:70
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
BoostedTauSeedsProducer::JetView
edm::View< reco::Jet > JetView
Definition: BoostedTauSeedsProducer.cc:55
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Ref.h
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
reco::PFJetCollection
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Definition: PFJetCollection.h:14
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
l1tstage2_dqm_sourceclient-live_cfg.invert
invert
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:85
Frameworkfwd.h
metsig::jet
Definition: SignAlgoResolutions.h:47
reco::PFCandidate::h0
Definition: PFCandidate.h:50
reco::PFJet
Jets made from PFObjects.
Definition: PFJet.h:20
EventSetup.h
reco::PFJet::Specific
Definition: PFJet.h:25
reco::PFJet::Specific::mChargedEmEnergy
float mChargedEmEnergy
Definition: PFJet.h:69
reco::LeafCandidate::energy
double energy() const final
energy
Definition: LeafCandidate.h:125
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
View.h
ParameterSet.h
BoostedTauSeedsProducer::JetToPFCandidateAssociation
edm::AssociationMap< edm::OneToMany< std::vector< reco::PFJet >, std::vector< reco::PFCandidate >, unsigned int > > JetToPFCandidateAssociation
Definition: BoostedTauSeedsProducer.cc:51
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
BoostedTauSeedsProducer::verbosity_
int verbosity_
Definition: BoostedTauSeedsProducer.cc:59
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
PFCandidateFwd.h