1 |
yilmaz |
1.3 |
#ifndef RecoHIJets_JetProducers_plugins_BackgroundJetProducer_h
|
2 |
|
|
#define RecoHIJets_JetProducers_plugins_BackgroundJetProducer_h
|
3 |
|
|
|
4 |
|
|
#include "MyVirtualJetProducer.h"
|
5 |
|
|
|
6 |
|
|
class BackgroundJetProducer : public MyVirtualJetProducer
|
7 |
|
|
{
|
8 |
|
|
|
9 |
|
|
public:
|
10 |
|
|
//
|
11 |
|
|
// construction/destruction
|
12 |
|
|
//
|
13 |
|
|
explicit BackgroundJetProducer(const edm::ParameterSet& iConfig);
|
14 |
|
|
virtual ~BackgroundJetProducer();
|
15 |
|
|
|
16 |
|
|
protected:
|
17 |
|
|
|
18 |
|
|
//
|
19 |
|
|
// member functions
|
20 |
|
|
//
|
21 |
|
|
|
22 |
|
|
virtual void runAlgorithm( edm::Event& iEvent, const edm::EventSetup& iSetup );
|
23 |
|
|
virtual void output( edm::Event & iEvent, edm::EventSetup const& iSetup );
|
24 |
|
|
template< typename T >
|
25 |
|
|
void writeBkgJets( edm::Event & iEvent, edm::EventSetup const& iSetup );
|
26 |
|
|
|
27 |
|
|
private:
|
28 |
|
|
|
29 |
|
|
// trackjet clustering parameters
|
30 |
|
|
bool useOnlyVertexTracks_;
|
31 |
|
|
bool useOnlyOnePV_;
|
32 |
|
|
float dzTrVtxMax_;
|
33 |
|
|
|
34 |
|
|
int nFill_;
|
35 |
|
|
float etaMax_;
|
36 |
|
|
bool avoidNegative_;
|
37 |
|
|
|
38 |
|
|
const CaloGeometry *geo;
|
39 |
|
|
};
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
#endif
|
43 |
yilmaz |
1.1 |
////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
//
|
45 |
|
|
// BackgroundJetProducer
|
46 |
|
|
// ------------------
|
47 |
|
|
//
|
48 |
|
|
// 04/21/2009 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
|
49 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
yilmaz |
1.3 |
//#include "RecoJets/JetProducers/plugins/BackgroundJetProducer.h"
|
52 |
yilmaz |
1.1 |
|
53 |
|
|
#include "RecoJets/JetProducers/interface/JetSpecific.h"
|
54 |
|
|
|
55 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
56 |
|
|
#include "FWCore/Framework/interface/EventSetup.h"
|
57 |
|
|
#include "FWCore/Framework/interface/ESHandle.h"
|
58 |
frankma |
1.4 |
#include "FWCore/Utilities/interface/Exception.h"
|
59 |
yilmaz |
1.1 |
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
60 |
|
|
#include "FWCore/Framework/interface/MakerMacros.h"
|
61 |
|
|
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
|
62 |
|
|
#include "FWCore/ServiceRegistry/interface/Service.h"
|
63 |
|
|
|
64 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
65 |
|
|
#include "DataFormats/VertexReco/interface/Vertex.h"
|
66 |
|
|
#include "DataFormats/VertexReco/interface/VertexFwd.h"
|
67 |
|
|
#include "DataFormats/JetReco/interface/CaloJetCollection.h"
|
68 |
|
|
#include "DataFormats/JetReco/interface/GenJetCollection.h"
|
69 |
|
|
#include "DataFormats/JetReco/interface/PFJetCollection.h"
|
70 |
|
|
#include "DataFormats/JetReco/interface/BasicJetCollection.h"
|
71 |
|
|
#include "DataFormats/Candidate/interface/CandidateFwd.h"
|
72 |
|
|
#include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
|
73 |
|
|
#include "DataFormats/Candidate/interface/LeafCandidate.h"
|
74 |
|
|
#include "DataFormats/Math/interface/deltaR.h"
|
75 |
|
|
|
76 |
|
|
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
|
77 |
|
|
#include "Geometry/Records/interface/CaloGeometryRecord.h"
|
78 |
|
|
|
79 |
|
|
#include "fastjet/SISConePlugin.hh"
|
80 |
|
|
#include "fastjet/CMSIterativeConePlugin.hh"
|
81 |
|
|
#include "fastjet/ATLASConePlugin.hh"
|
82 |
|
|
#include "fastjet/CDFMidPointPlugin.hh"
|
83 |
|
|
|
84 |
|
|
#include "CLHEP/Random/RandomEngine.h"
|
85 |
|
|
|
86 |
|
|
#include <iostream>
|
87 |
|
|
#include <memory>
|
88 |
|
|
#include <algorithm>
|
89 |
|
|
#include <limits>
|
90 |
|
|
#include <cmath>
|
91 |
|
|
|
92 |
|
|
using namespace std;
|
93 |
|
|
using namespace edm;
|
94 |
|
|
|
95 |
|
|
static const double pi = 3.14159265358979;
|
96 |
|
|
|
97 |
yilmaz |
1.3 |
CLHEP::HepRandomEngine* bkgRandomEngine;
|
98 |
yilmaz |
1.1 |
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
// construction / destruction
|
103 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
|
|
//______________________________________________________________________________
|
106 |
|
|
BackgroundJetProducer::BackgroundJetProducer(const edm::ParameterSet& iConfig)
|
107 |
yilmaz |
1.3 |
: MyVirtualJetProducer( iConfig ),
|
108 |
yilmaz |
1.1 |
nFill_(5),
|
109 |
yilmaz |
1.3 |
etaMax_(3),
|
110 |
|
|
geo(0)
|
111 |
yilmaz |
1.1 |
{
|
112 |
|
|
edm::Service<RandomNumberGenerator> rng;
|
113 |
yilmaz |
1.3 |
bkgRandomEngine = &(rng->getEngine());
|
114 |
yilmaz |
1.1 |
|
115 |
|
|
avoidNegative_ = iConfig.getParameter<bool>("avoidNegative");
|
116 |
|
|
|
117 |
|
|
if ( iConfig.exists("UseOnlyVertexTracks") )
|
118 |
|
|
useOnlyVertexTracks_ = iConfig.getParameter<bool>("UseOnlyVertexTracks");
|
119 |
|
|
else
|
120 |
|
|
useOnlyVertexTracks_ = false;
|
121 |
|
|
|
122 |
|
|
if ( iConfig.exists("UseOnlyOnePV") )
|
123 |
|
|
useOnlyOnePV_ = iConfig.getParameter<bool>("UseOnlyOnePV");
|
124 |
|
|
else
|
125 |
|
|
useOnlyOnePV_ = false;
|
126 |
|
|
|
127 |
|
|
if ( iConfig.exists("DrTrVtxMax") )
|
128 |
|
|
dzTrVtxMax_ = iConfig.getParameter<double>("DzTrVtxMax");
|
129 |
|
|
else
|
130 |
|
|
dzTrVtxMax_ = false;
|
131 |
|
|
|
132 |
|
|
produces<std::vector<bool> >("directions");
|
133 |
|
|
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
//______________________________________________________________________________
|
138 |
|
|
BackgroundJetProducer::~BackgroundJetProducer()
|
139 |
|
|
{
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
void BackgroundJetProducer::output(edm::Event & iEvent, edm::EventSetup const& iSetup)
|
143 |
|
|
{
|
144 |
|
|
// Write jets and constitutents. Will use fjJets_, inputs_
|
145 |
|
|
// and fjClusterSeq_
|
146 |
|
|
switch( jetTypeE ) {
|
147 |
|
|
case JetType::CaloJet :
|
148 |
|
|
writeBkgJets<reco::CaloJet>( iEvent, iSetup);
|
149 |
|
|
break;
|
150 |
|
|
case JetType::PFJet :
|
151 |
|
|
writeBkgJets<reco::PFJet>( iEvent, iSetup);
|
152 |
|
|
break;
|
153 |
|
|
case JetType::GenJet :
|
154 |
|
|
writeBkgJets<reco::GenJet>( iEvent, iSetup);
|
155 |
|
|
break;
|
156 |
|
|
case JetType::TrackJet :
|
157 |
|
|
writeBkgJets<reco::TrackJet>( iEvent, iSetup);
|
158 |
|
|
break;
|
159 |
|
|
case JetType::BasicJet :
|
160 |
|
|
writeBkgJets<reco::BasicJet>( iEvent, iSetup);
|
161 |
|
|
break;
|
162 |
|
|
default:
|
163 |
yilmaz |
1.3 |
edm::LogError("InvalidInput") << " invalid jet type in MyVirtualJetProducer\n";
|
164 |
yilmaz |
1.1 |
break;
|
165 |
|
|
};
|
166 |
|
|
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
template< typename T >
|
170 |
|
|
void BackgroundJetProducer::writeBkgJets( edm::Event & iEvent, edm::EventSetup const& iSetup )
|
171 |
|
|
{
|
172 |
|
|
// produce output jet collection
|
173 |
|
|
|
174 |
|
|
using namespace reco;
|
175 |
|
|
|
176 |
yilmaz |
1.3 |
if(!geo){
|
177 |
|
|
edm::ESHandle<CaloGeometry> pGeo;
|
178 |
|
|
iSetup.get<CaloGeometryRecord>().get(pGeo);
|
179 |
|
|
geo = pGeo.product();
|
180 |
|
|
}
|
181 |
|
|
|
182 |
yilmaz |
1.1 |
std::vector<fastjet::PseudoJet> fjFakeJets_;
|
183 |
|
|
std::vector<std::vector<reco::CandidatePtr> > constituents_;
|
184 |
|
|
vector<double> phiRandom;
|
185 |
|
|
vector<double> etaRandom;
|
186 |
|
|
vector<double> et;
|
187 |
|
|
vector<double> pileUp;
|
188 |
|
|
std::auto_ptr<std::vector<bool> > directions(new std::vector<bool>());
|
189 |
|
|
directions->reserve(nFill_);
|
190 |
|
|
|
191 |
|
|
phiRandom.reserve(nFill_);
|
192 |
|
|
etaRandom.reserve(nFill_);
|
193 |
|
|
et.reserve(nFill_);
|
194 |
|
|
pileUp.reserve(nFill_);
|
195 |
|
|
|
196 |
|
|
fjFakeJets_.reserve(nFill_);
|
197 |
|
|
constituents_.reserve(nFill_);
|
198 |
|
|
|
199 |
|
|
constituents_.reserve(nFill_);
|
200 |
|
|
for(int ijet = 0; ijet < nFill_; ++ijet){
|
201 |
|
|
vector<reco::CandidatePtr> vec;
|
202 |
|
|
constituents_.push_back(vec);
|
203 |
|
|
directions->push_back(true);
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
for(int ijet = 0; ijet < nFill_; ++ijet){
|
207 |
yilmaz |
1.3 |
phiRandom[ijet] = 2*pi*bkgRandomEngine->flat() - pi;
|
208 |
|
|
etaRandom[ijet] = 2*etaMax_*bkgRandomEngine->flat() - etaMax_;
|
209 |
yilmaz |
1.1 |
et[ijet] = 0;
|
210 |
|
|
pileUp[ijet] = 0;
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
for (vector<fastjet::PseudoJet>::const_iterator input_object = fjInputs_.begin (),
|
214 |
|
|
fjInputsEnd = fjInputs_.end();
|
215 |
|
|
input_object != fjInputsEnd; ++input_object) {
|
216 |
|
|
|
217 |
yilmaz |
1.3 |
const reco::CandidatePtr & tower=inputs_[input_object->user_index()];
|
218 |
|
|
const CaloTower* ctc = dynamic_cast<const CaloTower*>(tower.get());
|
219 |
|
|
int ieta = ctc->id().ieta();
|
220 |
|
|
int iphi = ctc->id().iphi();
|
221 |
|
|
CaloTowerDetId id(ieta,iphi);
|
222 |
|
|
const GlobalPoint& hitpoint = geo->getPosition(id);
|
223 |
|
|
double towEta = hitpoint.eta();
|
224 |
|
|
double towPhi = hitpoint.phi();
|
225 |
|
|
|
226 |
|
|
for(int ir = 0; ir < nFill_; ++ir){
|
227 |
|
|
if(reco::deltaR(towEta,towPhi,etaRandom[ir],phiRandom[ir]) > rParam_) continue;
|
228 |
|
|
|
229 |
|
|
constituents_[ir].push_back(tower);
|
230 |
|
|
|
231 |
|
|
double towet = tower->et();
|
232 |
|
|
double putow = subtractor_->getPileUpAtTower(tower);
|
233 |
|
|
double etadd = towet - putow;
|
234 |
|
|
if(avoidNegative_ && etadd < 0.) etadd = 0;
|
235 |
|
|
et[ir] += etadd;
|
236 |
|
|
pileUp[ir] += towet - etadd;
|
237 |
|
|
}
|
238 |
yilmaz |
1.1 |
}
|
239 |
yilmaz |
1.3 |
|
240 |
yilmaz |
1.1 |
cout<<"Start filling jets"<<endl;
|
241 |
|
|
|
242 |
|
|
for(int ir = 0; ir < nFill_; ++ir){
|
243 |
|
|
if(et[ir] < 0){
|
244 |
|
|
cout<<"Flipping vector"<<endl;
|
245 |
|
|
(*directions)[ir] = false;
|
246 |
|
|
et[ir] = -et[ir];
|
247 |
|
|
}else{
|
248 |
|
|
cout<<"Keep vector same"<<endl;
|
249 |
|
|
(*directions)[ir] = true;
|
250 |
|
|
}
|
251 |
|
|
cout<<"Lorentz"<<endl;
|
252 |
|
|
|
253 |
|
|
math::PtEtaPhiMLorentzVector p(et[ir],etaRandom[ir],phiRandom[ir],0);
|
254 |
|
|
fastjet::PseudoJet jet(p.px(),p.py(),p.pz(),p.energy());
|
255 |
|
|
fjFakeJets_.push_back(jet);
|
256 |
|
|
}
|
257 |
|
|
|
258 |
|
|
std::auto_ptr<std::vector<T> > jets(new std::vector<T>() );
|
259 |
|
|
jets->reserve(fjFakeJets_.size());
|
260 |
|
|
|
261 |
|
|
for (unsigned int ijet=0;ijet<fjFakeJets_.size();++ijet) {
|
262 |
|
|
// allocate this jet
|
263 |
|
|
T jet;
|
264 |
|
|
// get the fastjet jet
|
265 |
|
|
const fastjet::PseudoJet& fjJet = fjFakeJets_[ijet];
|
266 |
|
|
|
267 |
|
|
// convert them to CandidatePtr vector
|
268 |
|
|
std::vector<CandidatePtr> constituents =
|
269 |
|
|
constituents_[ijet];
|
270 |
|
|
|
271 |
|
|
writeSpecific(jet,
|
272 |
|
|
Particle::LorentzVector(fjJet.px(),
|
273 |
|
|
fjJet.py(),
|
274 |
|
|
fjJet.pz(),
|
275 |
|
|
fjJet.E()),
|
276 |
|
|
vertex_,
|
277 |
|
|
constituents, iSetup);
|
278 |
|
|
|
279 |
|
|
// calcuate the jet area
|
280 |
|
|
double jetArea=0.0;
|
281 |
|
|
jet.setJetArea (jetArea);
|
282 |
|
|
if(doPUOffsetCorr_){
|
283 |
|
|
jet.setPileup(pileUp[ijet]);
|
284 |
|
|
}else{
|
285 |
|
|
jet.setPileup (0.0);
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
// add to the list
|
289 |
|
|
jets->push_back(jet);
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
// put the jets in the collection
|
293 |
|
|
iEvent.put(jets);
|
294 |
|
|
iEvent.put(directions,"directions");
|
295 |
|
|
}
|
296 |
|
|
|
297 |
yilmaz |
1.3 |
void BackgroundJetProducer::runAlgorithm( edm::Event & iEvent, edm::EventSetup const& iSetup){
|
298 |
yilmaz |
1.1 |
if ( !doAreaFastjet_ && !doRhoFastjet_) {
|
299 |
|
|
fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequence( fjInputs_, *fjJetDefinition_ ) );
|
300 |
|
|
} else {
|
301 |
|
|
fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequenceArea( fjInputs_, *fjJetDefinition_ , *fjActiveArea_ ) );
|
302 |
|
|
}
|
303 |
|
|
fjJets_ = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
|
304 |
|
|
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
312 |
|
|
// define as cmssw plugin
|
313 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
314 |
|
|
|
315 |
|
|
DEFINE_FWK_MODULE(BackgroundJetProducer);
|
316 |
|
|
|