CMS 3D CMS Logo

HiL1Subtractor.cc
Go to the documentation of this file.
2 
3 #include <vector>
4 
5 using namespace std;
6 
7 //
8 // constants, enums and typedefs
9 //
10 double puCent[11] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
11 double medianPtkt[12];
12 
13 //
14 // static data member definitions
15 //
16 
17 //
18 // constructors and destructor
19 //
21  : jetType_(iConfig.getParameter<std::string>("jetType")),
22  rhoTagString_(iConfig.getParameter<std::string>("rhoTag"))
23 
24 {
25  rhoTag_ = (consumes<std::vector<double> >(rhoTagString_));
26 
27  if (jetType_ == "CaloJet") {
28  produces<reco::CaloJetCollection>();
29  caloJetSrc_ = (consumes<edm::View<reco::CaloJet> >(iConfig.getParameter<edm::InputTag>("src")));
30  } else if (jetType_ == "PFJet") {
31  produces<reco::PFJetCollection>();
32  pfJetSrc_ = (consumes<edm::View<reco::PFJet> >(iConfig.getParameter<edm::InputTag>("src")));
33  } else if (jetType_ == "GenJet") {
34  produces<reco::GenJetCollection>();
35  genJetSrc_ = (consumes<edm::View<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("src")));
36 
37  } else {
38  throw cms::Exception("InvalidInput") << "invalid jet type in HiL1Subtractor\n";
39  }
40 }
41 
43 
44 //
45 // member functions
46 //
47 
48 // ------------ method called to produce the data ------------
50  // get the input jet collection and create output jet collection
51 
52  // right now, identical loop for calo and PF jets, should template
53  if (jetType_ == "GenJet") {
54  auto jets = std::make_unique<reco::GenJetCollection>();
56  iEvent.getByToken(genJetSrc_, h_jets);
57 
58  // Grab appropriate rho, hard coded for the moment
60  iEvent.getByToken(rhoTag_, rs);
61 
62  int rsize = rs->size();
63 
64  for (int j = 0; j < rsize; j++) {
65  double medianpt = rs->at(j);
66  medianPtkt[j] = medianpt;
67  }
68 
69  // loop over the jets
70  int jetsize = h_jets->size();
71  for (int ijet = 0; ijet < jetsize; ++ijet) {
72  reco::GenJet jet = ((*h_jets)[ijet]);
73 
74  double jet_eta = jet.eta();
75  double jet_et = jet.et();
76 
77  //std::cout<<" pre-subtracted jet_et "<<jet_et<<std::endl;
78 
79  if (fabs(jet_eta) <= 3) {
80  double rho = -999;
81 
82  if (jet_eta < -2.5 && jet_eta > -3.5)
83  rho = medianPtkt[2];
84  if (jet_eta < -1.5 && jet_eta > -2.5)
85  rho = medianPtkt[3];
86  if (jet_eta < -0.5 && jet_eta > -1.5)
87  rho = medianPtkt[4];
88  if (jet_eta < 0.5 && jet_eta > -0.5)
89  rho = medianPtkt[5];
90  if (jet_eta < 1.5 && jet_eta > 0.5)
91  rho = medianPtkt[6];
92  if (jet_eta < 2.5 && jet_eta > 1.5)
93  rho = medianPtkt[7];
94  if (jet_eta < 3.5 && jet_eta > 2.5)
95  rho = medianPtkt[8];
96 
97  double jet_area = jet.jetArea();
98 
99  double CorrFactor = 0.;
100  if (rho * jet_area < jet_et)
101  CorrFactor = 1.0 - rho * jet_area / jet_et;
102  jet.scaleEnergy(CorrFactor);
103  jet.setPileup(rho * jet_area);
104 
105  //std::cout<<" correction factor "<<1.0 - rho*jet_area/jet_et<<std::endl;
106  }
107 
108  //std::cout<<" subtracted jet_et "<<jet.et()<<std::endl;
109  jets->push_back(jet);
110  }
111  iEvent.put(std::move(jets));
112 
113  } else if (jetType_ == "CaloJet") {
114  auto jets = std::make_unique<reco::CaloJetCollection>();
116  iEvent.getByToken(caloJetSrc_, h_jets);
117 
118  // Grab appropriate rho, hard coded for the moment
120  iEvent.getByToken(rhoTag_, rs);
121 
122  int rsize = rs->size();
123 
124  for (int j = 0; j < rsize; j++) {
125  double medianpt = rs->at(j);
126  medianPtkt[j] = medianpt;
127  }
128 
129  // loop over the jets
130 
131  int jetsize = h_jets->size();
132 
133  for (int ijet = 0; ijet < jetsize; ++ijet) {
134  reco::CaloJet jet = ((*h_jets)[ijet]);
135 
136  double jet_eta = jet.eta();
137  double jet_et = jet.et();
138 
139  //std::cout<<" pre-subtracted jet_et "<<jet_et<<std::endl;
140 
141  if (fabs(jet_eta) <= 3) {
142  double rho = -999;
143 
144  if (jet_eta < -2.5 && jet_eta > -3.5)
145  rho = medianPtkt[2];
146  if (jet_eta < -1.5 && jet_eta > -2.5)
147  rho = medianPtkt[3];
148  if (jet_eta < -0.5 && jet_eta > -1.5)
149  rho = medianPtkt[4];
150  if (jet_eta < 0.5 && jet_eta > -0.5)
151  rho = medianPtkt[5];
152  if (jet_eta < 1.5 && jet_eta > 0.5)
153  rho = medianPtkt[6];
154  if (jet_eta < 2.5 && jet_eta > 1.5)
155  rho = medianPtkt[7];
156  if (jet_eta < 3.5 && jet_eta > 2.5)
157  rho = medianPtkt[8];
158 
159  double jet_area = jet.jetArea();
160 
161  double CorrFactor = 0.;
162  if (rho * jet_area < jet_et)
163  CorrFactor = 1.0 - rho * jet_area / jet_et;
164  jet.scaleEnergy(CorrFactor);
165  jet.setPileup(rho * jet_area);
166 
167  //std::cout<<" correction factor "<<1.0 - rho*jet_area/jet_et<<std::endl;
168  }
169 
170  //std::cout<<" subtracted jet_et "<<jet.et()<<std::endl;
171 
172  jets->push_back(jet);
173  }
174  iEvent.put(std::move(jets));
175 
176  } else if (jetType_ == "PFJet") {
177  auto jets = std::make_unique<reco::PFJetCollection>();
179  iEvent.getByToken(pfJetSrc_, h_jets);
180 
181  // Grab appropriate rho, hard coded for the moment
183  iEvent.getByToken(rhoTag_, rs);
184 
185  int rsize = rs->size();
186 
187  for (int j = 0; j < rsize; j++) {
188  double medianpt = rs->at(j);
189  medianPtkt[j] = medianpt;
190  }
191 
192  // loop over the jets
193 
194  int jetsize = h_jets->size();
195 
196  for (int ijet = 0; ijet < jetsize; ++ijet) {
197  reco::PFJet jet = ((*h_jets)[ijet]);
198 
199  double jet_eta = jet.eta();
200  double jet_et = jet.et();
201 
202  //std::cout<<" pre-subtracted jet_et "<<jet_et<<std::endl;
203 
204  if (fabs(jet_eta) <= 3) {
205  double rho = -999;
206 
207  if (jet_eta < -2.5 && jet_eta > -3.5)
208  rho = medianPtkt[2];
209  if (jet_eta < -1.5 && jet_eta > -2.5)
210  rho = medianPtkt[3];
211  if (jet_eta < -0.5 && jet_eta > -1.5)
212  rho = medianPtkt[4];
213  if (jet_eta < 0.5 && jet_eta > -0.5)
214  rho = medianPtkt[5];
215  if (jet_eta < 1.5 && jet_eta > 0.5)
216  rho = medianPtkt[6];
217  if (jet_eta < 2.5 && jet_eta > 1.5)
218  rho = medianPtkt[7];
219  if (jet_eta < 3.5 && jet_eta > 2.5)
220  rho = medianPtkt[8];
221 
222  double jet_area = jet.jetArea();
223 
224  double CorrFactor = 0.;
225  if (rho * jet_area < jet_et)
226  CorrFactor = 1.0 - rho * jet_area / jet_et;
227  jet.scaleEnergy(CorrFactor);
228  jet.setPileup(rho * jet_area);
229 
230  //std::cout<<" correction factor "<<1.0 - rho*jet_area/jet_et<<std::endl;
231  }
232 
233  //std::cout<<" subtracted jet_et "<<jet.et()<<std::endl;
234 
235  jets->push_back(jet);
236  }
237  iEvent.put(std::move(jets));
238  }
239 }
240 
241 // ------------ method called once each job just before starting event loop ------------
243 
244 // ------------ method called once each job just after ending the event loop ------------
246 
247 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Jets made from CaloTowers.
Definition: CaloJet.h:27
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double puCent[11]
HiL1Subtractor(const edm::ParameterSet &)
Jets made from PFObjects.
Definition: PFJet.h:20
void beginJob() override
std::string rhoTagString_
std::string jetType_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::View< reco::GenJet > > genJetSrc_
double medianPtkt[12]
void produce(edm::Event &, const edm::EventSetup &) override
Jets made from MC generator particles.
Definition: GenJet.h:23
edm::EDGetTokenT< edm::View< reco::CaloJet > > caloJetSrc_
void endJob() override
edm::EDGetTokenT< edm::View< reco::PFJet > > pfJetSrc_
~HiL1Subtractor() override
edm::EDGetTokenT< std::vector< double > > rhoTag_
def move(src, dest)
Definition: eostools.py:511