CMS 3D CMS Logo

PileupJetIDVarProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <vector>
3 
12 
14 public:
15  explicit PileupJetIDVarProducer(const edm::ParameterSet& iConfig)
16  : srcJet_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("srcJet"))),
18  consumes<edm::ValueMap<StoredPileupJetIdentifier>>(iConfig.getParameter<edm::InputTag>("srcPileupJetId"))) {
19  produces<edm::ValueMap<float>>("dR2Mean");
20  produces<edm::ValueMap<float>>("majW");
21  produces<edm::ValueMap<float>>("minW");
22  produces<edm::ValueMap<float>>("frac01");
23  produces<edm::ValueMap<float>>("frac02");
24  produces<edm::ValueMap<float>>("frac03");
25  produces<edm::ValueMap<float>>("frac04");
26  produces<edm::ValueMap<float>>("ptD");
27  produces<edm::ValueMap<float>>("beta");
28  produces<edm::ValueMap<float>>("pull");
29  produces<edm::ValueMap<float>>("jetR");
30  produces<edm::ValueMap<float>>("jetRchg");
31  produces<edm::ValueMap<int>>("nCharged");
32  }
34 
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36 
37 private:
38  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
39 
40  // ----------member data ---------------------------
43 };
44 
45 // ------------ method called to produce the data ------------
49 
50  iEvent.getByToken(srcJet_, srcJet);
51  iEvent.getByToken(srcPileupJetId_, srcPileupJetId);
52 
53  unsigned int nJet = srcJet->size();
54 
55  std::vector<float> dR2Mean(nJet, -1);
56  std::vector<float> majW(nJet, -1);
57  std::vector<float> minW(nJet, -1);
58  std::vector<float> frac01(nJet, -1);
59  std::vector<float> frac02(nJet, -1);
60  std::vector<float> frac03(nJet, -1);
61  std::vector<float> frac04(nJet, -1);
62  std::vector<float> ptD(nJet, -1);
63  std::vector<float> beta(nJet, -1);
64  std::vector<float> pull(nJet, -1);
65  std::vector<float> jetR(nJet, -1);
66  std::vector<float> jetRchg(nJet, -1);
67  std::vector<int> nCharged(nJet, -1);
68 
69  for (unsigned int ij = 0; ij < nJet; ij++) {
70  auto jet = srcJet->ptrAt(ij);
71 
72  edm::RefToBase<pat::Jet> jetRef = srcJet->refAt(ij);
73 
74  dR2Mean[ij] = (*srcPileupJetId)[jetRef].dR2Mean();
75  majW[ij] = (*srcPileupJetId)[jetRef].majW();
76  minW[ij] = (*srcPileupJetId)[jetRef].minW();
77  frac01[ij] = (*srcPileupJetId)[jetRef].frac01();
78  frac02[ij] = (*srcPileupJetId)[jetRef].frac02();
79  frac03[ij] = (*srcPileupJetId)[jetRef].frac03();
80  frac04[ij] = (*srcPileupJetId)[jetRef].frac04();
81  ptD[ij] = (*srcPileupJetId)[jetRef].ptD();
82  beta[ij] = (*srcPileupJetId)[jetRef].beta();
83  pull[ij] = (*srcPileupJetId)[jetRef].pull();
84  jetR[ij] = (*srcPileupJetId)[jetRef].jetR();
85  jetRchg[ij] = (*srcPileupJetId)[jetRef].jetRchg();
86  nCharged[ij] = (*srcPileupJetId)[jetRef].nCharged();
87  }
88 
89  std::unique_ptr<edm::ValueMap<float>> dR2MeanV(new edm::ValueMap<float>());
90  edm::ValueMap<float>::Filler filler_dR2Mean(*dR2MeanV);
91  filler_dR2Mean.insert(srcJet, dR2Mean.begin(), dR2Mean.end());
92  filler_dR2Mean.fill();
93  iEvent.put(std::move(dR2MeanV), "dR2Mean");
94 
95  std::unique_ptr<edm::ValueMap<float>> majWV(new edm::ValueMap<float>());
96  edm::ValueMap<float>::Filler filler_majW(*majWV);
97  filler_majW.insert(srcJet, majW.begin(), majW.end());
98  filler_majW.fill();
99  iEvent.put(std::move(majWV), "majW");
100 
101  std::unique_ptr<edm::ValueMap<float>> minWV(new edm::ValueMap<float>());
102  edm::ValueMap<float>::Filler filler_minW(*minWV);
103  filler_minW.insert(srcJet, minW.begin(), minW.end());
104  filler_minW.fill();
105  iEvent.put(std::move(minWV), "minW");
106 
107  std::unique_ptr<edm::ValueMap<float>> frac01V(new edm::ValueMap<float>());
108  edm::ValueMap<float>::Filler filler_frac01(*frac01V);
109  filler_frac01.insert(srcJet, frac01.begin(), frac01.end());
110  filler_frac01.fill();
111  iEvent.put(std::move(frac01V), "frac01");
112 
113  std::unique_ptr<edm::ValueMap<float>> frac02V(new edm::ValueMap<float>());
114  edm::ValueMap<float>::Filler filler_frac02(*frac02V);
115  filler_frac02.insert(srcJet, frac02.begin(), frac02.end());
116  filler_frac02.fill();
117  iEvent.put(std::move(frac02V), "frac02");
118 
119  std::unique_ptr<edm::ValueMap<float>> frac03V(new edm::ValueMap<float>());
120  edm::ValueMap<float>::Filler filler_frac03(*frac03V);
121  filler_frac03.insert(srcJet, frac03.begin(), frac03.end());
122  filler_frac03.fill();
123  iEvent.put(std::move(frac03V), "frac03");
124 
125  std::unique_ptr<edm::ValueMap<float>> frac04V(new edm::ValueMap<float>());
126  edm::ValueMap<float>::Filler filler_frac04(*frac04V);
127  filler_frac04.insert(srcJet, frac04.begin(), frac04.end());
128  filler_frac04.fill();
129  iEvent.put(std::move(frac04V), "frac04");
130 
131  std::unique_ptr<edm::ValueMap<float>> ptDV(new edm::ValueMap<float>());
132  edm::ValueMap<float>::Filler filler_ptD(*ptDV);
133  filler_ptD.insert(srcJet, ptD.begin(), ptD.end());
134  filler_ptD.fill();
135  iEvent.put(std::move(ptDV), "ptD");
136 
137  std::unique_ptr<edm::ValueMap<float>> betaV(new edm::ValueMap<float>());
138  edm::ValueMap<float>::Filler filler_beta(*betaV);
139  filler_beta.insert(srcJet, beta.begin(), beta.end());
140  filler_beta.fill();
141  iEvent.put(std::move(betaV), "beta");
142 
143  std::unique_ptr<edm::ValueMap<float>> pullV(new edm::ValueMap<float>());
144  edm::ValueMap<float>::Filler filler_pull(*pullV);
145  filler_pull.insert(srcJet, pull.begin(), pull.end());
146  filler_pull.fill();
147  iEvent.put(std::move(pullV), "pull");
148 
149  std::unique_ptr<edm::ValueMap<float>> jetRV(new edm::ValueMap<float>());
150  edm::ValueMap<float>::Filler filler_jetR(*jetRV);
151  filler_jetR.insert(srcJet, jetR.begin(), jetR.end());
152  filler_jetR.fill();
153  iEvent.put(std::move(jetRV), "jetR");
154 
155  std::unique_ptr<edm::ValueMap<float>> jetRchgV(new edm::ValueMap<float>());
156  edm::ValueMap<float>::Filler filler_jetRchg(*jetRchgV);
157  filler_jetRchg.insert(srcJet, jetRchg.begin(), jetRchg.end());
158  filler_jetRchg.fill();
159  iEvent.put(std::move(jetRchgV), "jetRchg");
160 
161  std::unique_ptr<edm::ValueMap<int>> nChargedV(new edm::ValueMap<int>());
162  edm::ValueMap<int>::Filler filler_nCharged(*nChargedV);
163  filler_nCharged.insert(srcJet, nCharged.begin(), nCharged.end());
164  filler_nCharged.fill();
165  iEvent.put(std::move(nChargedV), "nCharged");
166 }
167 
168 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
170  //The following says we do not know what parameters are allowed so do no validation
171  // Please change this to state exactly what you do use, even if it is no parameters
173  desc.add<edm::InputTag>("srcJet")->setComment("jet input collection");
174  desc.add<edm::InputTag>("srcPileupJetId")->setComment("StoredPileupJetIdentifier name");
176  modname += "PileupJetIDVarProducer";
177  descriptions.add(modname, desc);
178 }
179 
180 //define this as a plug-in
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > srcPileupJetId_
Definition: Jet.py:1
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
PileupJetIDVarProducer(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:511