CMS 3D CMS Logo

PATPuppiJetSpecificsProducer.cc
Go to the documentation of this file.
1 /*
2  * PATPuppiJetSpecificProducer
3  *
4  * Author: Andreas Hinzmann
5  *
6  * Compute weighted constituent multiplicites for PUPPI PAT jets
7  *
8  */
9 
16 
19 
23 
25 public:
28  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
29  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
30 
31 private:
32  // input collection
35 };
36 
38  srcjets_ = cfg.getParameter<edm::InputTag>("src");
39  jets_token = consumes<edm::View<pat::Jet> >(srcjets_);
40 
41  produces<edm::ValueMap<float> >("puppiMultiplicity");
42  produces<edm::ValueMap<float> >("neutralPuppiMultiplicity");
43  produces<edm::ValueMap<float> >("neutralHadronPuppiMultiplicity");
44  produces<edm::ValueMap<float> >("photonPuppiMultiplicity");
45  produces<edm::ValueMap<float> >("HFHadronPuppiMultiplicity");
46  produces<edm::ValueMap<float> >("HFEMPuppiMultiplicity");
47 }
48 
52 
53  std::vector<float> puppiMultiplicities;
54  std::vector<float> neutralPuppiMultiplicities;
55  std::vector<float> neutralHadronPuppiMultiplicities;
56  std::vector<float> photonPuppiMultiplicities;
57  std::vector<float> HFHadronPuppiMultiplicities;
58  std::vector<float> HFEMPuppiMultiplicities;
59 
60  for (auto const& c : *jets) {
61  float puppiMultiplicity = 0;
62  float neutralPuppiMultiplicity = 0;
63  float neutralHadronPuppiMultiplicity = 0;
64  float photonPuppiMultiplicity = 0;
65  float HFHadronPuppiMultiplicity = 0;
66  float HFEMPuppiMultiplicity = 0;
67 
68  for (unsigned i = 0; i < c.numberOfDaughters(); i++) {
69  const pat::PackedCandidate& dau = static_cast<const pat::PackedCandidate&>(*c.daughter(i));
70  auto weight = dau.puppiWeight();
71  puppiMultiplicity += weight;
72  // This logic is taken from RecoJets/JetProducers/src/JetSpecific.cc
73  switch (std::abs(dau.pdgId())) {
74  case 130: //PFCandidate::h0 : // neutral hadron
75  neutralHadronPuppiMultiplicity += weight;
76  neutralPuppiMultiplicity += weight;
77  break;
78  case 22: //PFCandidate::gamma: // photon
79  photonPuppiMultiplicity += weight;
80  neutralPuppiMultiplicity += weight;
81  break;
82  case 1: // PFCandidate::h_HF : // hadron in HF
83  HFHadronPuppiMultiplicity += weight;
84  neutralPuppiMultiplicity += weight;
85  break;
86  case 2: //PFCandidate::egamma_HF : // electromagnetic in HF
87  HFEMPuppiMultiplicity += weight;
88  neutralPuppiMultiplicity += weight;
89  break;
90  }
91  }
92 
93  puppiMultiplicities.push_back(puppiMultiplicity);
94  neutralPuppiMultiplicities.push_back(neutralPuppiMultiplicity);
95  neutralHadronPuppiMultiplicities.push_back(neutralHadronPuppiMultiplicity);
96  photonPuppiMultiplicities.push_back(photonPuppiMultiplicity);
97  HFHadronPuppiMultiplicities.push_back(HFHadronPuppiMultiplicity);
98  HFEMPuppiMultiplicities.push_back(HFEMPuppiMultiplicity);
99  }
100 
101  std::unique_ptr<edm::ValueMap<float> > puppiMultiplicities_out(new edm::ValueMap<float>());
102  edm::ValueMap<float>::Filler puppiMultiplicities_filler(*puppiMultiplicities_out);
103  puppiMultiplicities_filler.insert(jets, puppiMultiplicities.begin(), puppiMultiplicities.end());
104  puppiMultiplicities_filler.fill();
105  evt.put(std::move(puppiMultiplicities_out), "puppiMultiplicity");
106 
107  std::unique_ptr<edm::ValueMap<float> > neutralPuppiMultiplicities_out(new edm::ValueMap<float>());
108  edm::ValueMap<float>::Filler neutralPuppiMultiplicities_filler(*neutralPuppiMultiplicities_out);
109  neutralPuppiMultiplicities_filler.insert(jets, neutralPuppiMultiplicities.begin(), neutralPuppiMultiplicities.end());
110  neutralPuppiMultiplicities_filler.fill();
111  evt.put(std::move(neutralPuppiMultiplicities_out), "neutralPuppiMultiplicity");
112 
113  std::unique_ptr<edm::ValueMap<float> > neutralHadronPuppiMultiplicities_out(new edm::ValueMap<float>());
114  edm::ValueMap<float>::Filler neutralHadronPuppiMultiplicities_filler(*neutralHadronPuppiMultiplicities_out);
115  neutralHadronPuppiMultiplicities_filler.insert(
116  jets, neutralHadronPuppiMultiplicities.begin(), neutralHadronPuppiMultiplicities.end());
117  neutralHadronPuppiMultiplicities_filler.fill();
118  evt.put(std::move(neutralHadronPuppiMultiplicities_out), "neutralHadronPuppiMultiplicity");
119 
120  std::unique_ptr<edm::ValueMap<float> > photonPuppiMultiplicities_out(new edm::ValueMap<float>());
121  edm::ValueMap<float>::Filler photonPuppiMultiplicities_filler(*photonPuppiMultiplicities_out);
122  photonPuppiMultiplicities_filler.insert(jets, photonPuppiMultiplicities.begin(), photonPuppiMultiplicities.end());
123  photonPuppiMultiplicities_filler.fill();
124  evt.put(std::move(photonPuppiMultiplicities_out), "photonPuppiMultiplicity");
125 
126  std::unique_ptr<edm::ValueMap<float> > HFHadronPuppiMultiplicities_out(new edm::ValueMap<float>());
127  edm::ValueMap<float>::Filler HFHadronPuppiMultiplicities_filler(*HFHadronPuppiMultiplicities_out);
128  HFHadronPuppiMultiplicities_filler.insert(
129  jets, HFHadronPuppiMultiplicities.begin(), HFHadronPuppiMultiplicities.end());
130  HFHadronPuppiMultiplicities_filler.fill();
131  evt.put(std::move(HFHadronPuppiMultiplicities_out), "HFHadronPuppiMultiplicity");
132 
133  std::unique_ptr<edm::ValueMap<float> > HFEMPuppiMultiplicities_out(new edm::ValueMap<float>());
134  edm::ValueMap<float>::Filler HFEMPuppiMultiplicities_filler(*HFEMPuppiMultiplicities_out);
135  HFEMPuppiMultiplicities_filler.insert(jets, HFEMPuppiMultiplicities.begin(), HFEMPuppiMultiplicities.end());
136  HFEMPuppiMultiplicities_filler.fill();
137  evt.put(std::move(HFEMPuppiMultiplicities_out), "HFEMPuppiMultiplicity");
138 }
139 
142  desc.add<edm::InputTag>("src", edm::InputTag("slimmedJets"));
143  descriptions.add("patPuppiJetSpecificProducer", desc);
144 }
145 
147 
float puppiWeight() const
edm::EDGetTokenT< edm::View< pat::Jet > > jets_token
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
Definition: weight.py:1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
int pdgId() const override
PDG identifier.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
PATPuppiJetSpecificProducer(const edm::ParameterSet &cfg)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
def move(src, dest)
Definition: eostools.py:511