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