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 ------------
47  auto srcJet = iEvent.getHandle(srcJet_);
48  const auto& pileupJetIdProd = iEvent.get(srcPileupJetId_);
49 
50  unsigned int nJet = srcJet->size();
51 
52  std::vector<float> dR2Mean(nJet, -1);
53  std::vector<float> majW(nJet, -1);
54  std::vector<float> minW(nJet, -1);
55  std::vector<float> frac01(nJet, -1);
56  std::vector<float> frac02(nJet, -1);
57  std::vector<float> frac03(nJet, -1);
58  std::vector<float> frac04(nJet, -1);
59  std::vector<float> ptD(nJet, -1);
60  std::vector<float> beta(nJet, -1);
61  std::vector<float> pull(nJet, -1);
62  std::vector<float> jetR(nJet, -1);
63  std::vector<float> jetRchg(nJet, -1);
64  std::vector<int> nCharged(nJet, -1);
65 
66  for (unsigned int ij = 0; ij < nJet; ij++) {
67  auto jet = srcJet->ptrAt(ij);
68 
69  edm::RefToBase<pat::Jet> jetRef = srcJet->refAt(ij);
70 
71  dR2Mean[ij] = pileupJetIdProd[jetRef].dR2Mean();
72  majW[ij] = pileupJetIdProd[jetRef].majW();
73  minW[ij] = pileupJetIdProd[jetRef].minW();
74  frac01[ij] = pileupJetIdProd[jetRef].frac01();
75  frac02[ij] = pileupJetIdProd[jetRef].frac02();
76  frac03[ij] = pileupJetIdProd[jetRef].frac03();
77  frac04[ij] = pileupJetIdProd[jetRef].frac04();
78  ptD[ij] = pileupJetIdProd[jetRef].ptD();
79  beta[ij] = pileupJetIdProd[jetRef].beta();
80  pull[ij] = pileupJetIdProd[jetRef].pull();
81  jetR[ij] = pileupJetIdProd[jetRef].jetR();
82  jetRchg[ij] = pileupJetIdProd[jetRef].jetRchg();
83  nCharged[ij] = pileupJetIdProd[jetRef].nCharged();
84  }
85 
86  std::unique_ptr<edm::ValueMap<float>> dR2MeanV(new edm::ValueMap<float>());
87  edm::ValueMap<float>::Filler filler_dR2Mean(*dR2MeanV);
88  filler_dR2Mean.insert(srcJet, dR2Mean.begin(), dR2Mean.end());
89  filler_dR2Mean.fill();
90  iEvent.put(std::move(dR2MeanV), "dR2Mean");
91 
92  std::unique_ptr<edm::ValueMap<float>> majWV(new edm::ValueMap<float>());
93  edm::ValueMap<float>::Filler filler_majW(*majWV);
94  filler_majW.insert(srcJet, majW.begin(), majW.end());
95  filler_majW.fill();
96  iEvent.put(std::move(majWV), "majW");
97 
98  std::unique_ptr<edm::ValueMap<float>> minWV(new edm::ValueMap<float>());
99  edm::ValueMap<float>::Filler filler_minW(*minWV);
100  filler_minW.insert(srcJet, minW.begin(), minW.end());
101  filler_minW.fill();
102  iEvent.put(std::move(minWV), "minW");
103 
104  std::unique_ptr<edm::ValueMap<float>> frac01V(new edm::ValueMap<float>());
105  edm::ValueMap<float>::Filler filler_frac01(*frac01V);
106  filler_frac01.insert(srcJet, frac01.begin(), frac01.end());
107  filler_frac01.fill();
108  iEvent.put(std::move(frac01V), "frac01");
109 
110  std::unique_ptr<edm::ValueMap<float>> frac02V(new edm::ValueMap<float>());
111  edm::ValueMap<float>::Filler filler_frac02(*frac02V);
112  filler_frac02.insert(srcJet, frac02.begin(), frac02.end());
113  filler_frac02.fill();
114  iEvent.put(std::move(frac02V), "frac02");
115 
116  std::unique_ptr<edm::ValueMap<float>> frac03V(new edm::ValueMap<float>());
117  edm::ValueMap<float>::Filler filler_frac03(*frac03V);
118  filler_frac03.insert(srcJet, frac03.begin(), frac03.end());
119  filler_frac03.fill();
120  iEvent.put(std::move(frac03V), "frac03");
121 
122  std::unique_ptr<edm::ValueMap<float>> frac04V(new edm::ValueMap<float>());
123  edm::ValueMap<float>::Filler filler_frac04(*frac04V);
124  filler_frac04.insert(srcJet, frac04.begin(), frac04.end());
125  filler_frac04.fill();
126  iEvent.put(std::move(frac04V), "frac04");
127 
128  std::unique_ptr<edm::ValueMap<float>> ptDV(new edm::ValueMap<float>());
129  edm::ValueMap<float>::Filler filler_ptD(*ptDV);
130  filler_ptD.insert(srcJet, ptD.begin(), ptD.end());
131  filler_ptD.fill();
132  iEvent.put(std::move(ptDV), "ptD");
133 
134  std::unique_ptr<edm::ValueMap<float>> betaV(new edm::ValueMap<float>());
135  edm::ValueMap<float>::Filler filler_beta(*betaV);
136  filler_beta.insert(srcJet, beta.begin(), beta.end());
137  filler_beta.fill();
138  iEvent.put(std::move(betaV), "beta");
139 
140  std::unique_ptr<edm::ValueMap<float>> pullV(new edm::ValueMap<float>());
141  edm::ValueMap<float>::Filler filler_pull(*pullV);
142  filler_pull.insert(srcJet, pull.begin(), pull.end());
143  filler_pull.fill();
144  iEvent.put(std::move(pullV), "pull");
145 
146  std::unique_ptr<edm::ValueMap<float>> jetRV(new edm::ValueMap<float>());
147  edm::ValueMap<float>::Filler filler_jetR(*jetRV);
148  filler_jetR.insert(srcJet, jetR.begin(), jetR.end());
149  filler_jetR.fill();
150  iEvent.put(std::move(jetRV), "jetR");
151 
152  std::unique_ptr<edm::ValueMap<float>> jetRchgV(new edm::ValueMap<float>());
153  edm::ValueMap<float>::Filler filler_jetRchg(*jetRchgV);
154  filler_jetRchg.insert(srcJet, jetRchg.begin(), jetRchg.end());
155  filler_jetRchg.fill();
156  iEvent.put(std::move(jetRchgV), "jetRchg");
157 
158  std::unique_ptr<edm::ValueMap<int>> nChargedV(new edm::ValueMap<int>());
159  edm::ValueMap<int>::Filler filler_nCharged(*nChargedV);
160  filler_nCharged.insert(srcJet, nCharged.begin(), nCharged.end());
161  filler_nCharged.fill();
162  iEvent.put(std::move(nChargedV), "nCharged");
163 }
164 
165 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
167  //The following says we do not know what parameters are allowed so do no validation
168  // Please change this to state exactly what you do use, even if it is no parameters
170  desc.add<edm::InputTag>("srcJet")->setComment("pat::Jet input collection");
171  desc.add<edm::InputTag>("srcPileupJetId")->setComment("StoredPileupJetIdentifier ValueMap input collection");
172  descriptions.addWithDefaultLabel(desc);
173 }
174 
175 //define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
HLT enums.
PileupJetIDVarProducer(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:511