Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00008
00009 #include "RecoJets/JetProducers/plugins/FastjetJetProducer.h"
00010
00011 #include "RecoJets/JetProducers/interface/JetSpecific.h"
00012
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018
00019 #include "DataFormats/Common/interface/Handle.h"
00020 #include "DataFormats/VertexReco/interface/Vertex.h"
00021 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00022 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00023 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00024 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00025 #include "DataFormats/JetReco/interface/BasicJetCollection.h"
00026 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00027 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00028 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00029
00030
00031 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00032 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00033
00034 #include "fastjet/SISConePlugin.hh"
00035 #include "fastjet/CMSIterativeConePlugin.hh"
00036 #include "fastjet/ATLASConePlugin.hh"
00037 #include "fastjet/CDFMidPointPlugin.hh"
00038
00039
00040 #include <iostream>
00041 #include <memory>
00042 #include <algorithm>
00043 #include <limits>
00044 #include <cmath>
00045
00046
00047 using namespace std;
00048
00049
00050
00052
00054
00055
00056 FastjetJetProducer::FastjetJetProducer(const edm::ParameterSet& iConfig)
00057 : VirtualJetProducer( iConfig )
00058 {
00059
00060 if ( iConfig.exists("UseOnlyVertexTracks") )
00061 useOnlyVertexTracks_ = iConfig.getParameter<bool>("UseOnlyVertexTracks");
00062 else
00063 useOnlyVertexTracks_ = false;
00064
00065 if ( iConfig.exists("UseOnlyOnePV") )
00066 useOnlyOnePV_ = iConfig.getParameter<bool>("UseOnlyOnePV");
00067 else
00068 useOnlyOnePV_ = false;
00069
00070 if ( iConfig.exists("DzTrVtxMax") )
00071 dzTrVtxMax_ = iConfig.getParameter<double>("DzTrVtxMax");
00072 else
00073 dzTrVtxMax_ = 999999.;
00074 if ( iConfig.exists("DxyTrVtxMax") )
00075 dxyTrVtxMax_ = iConfig.getParameter<double>("DxyTrVtxMax");
00076 else
00077 dxyTrVtxMax_ = 999999.;
00078 if ( iConfig.exists("MinVtxNdof") )
00079 minVtxNdof_ = iConfig.getParameter<int>("MinVtxNdof");
00080 else
00081 minVtxNdof_ = 5;
00082 if ( iConfig.exists("MaxVtxZ") )
00083 maxVtxZ_ = iConfig.getParameter<double>("MaxVtxZ");
00084 else
00085 maxVtxZ_ = 15;
00086
00087 }
00088
00089
00090
00091 FastjetJetProducer::~FastjetJetProducer()
00092 {
00093 }
00094
00095
00097
00099
00100 void FastjetJetProducer::produce( edm::Event & iEvent, const edm::EventSetup & iSetup )
00101 {
00102
00103
00104 if (!makeTrackJet(jetTypeE)) {
00105
00106
00107 VirtualJetProducer::produce( iEvent, iSetup );
00108
00109 } else {
00110
00111 produceTrackJets(iEvent, iSetup);
00112
00113 }
00114
00115 }
00116
00117
00118 void FastjetJetProducer::produceTrackJets( edm::Event & iEvent, const edm::EventSetup & iSetup )
00119 {
00120
00121
00122 edm::Handle<edm::View<reco::RecoChargedRefCandidate> > inputsHandle;
00123 iEvent.getByLabel(src_, inputsHandle);
00124
00125 std::vector<edm::Ptr<reco::RecoChargedRefCandidate> > allInputs;
00126 std::vector<edm::Ptr<reco::Candidate> > origInputs;
00127 for (size_t i = 0; i < inputsHandle->size(); ++i) {
00128 allInputs.push_back(inputsHandle->ptrAt(i));
00129 origInputs.push_back(inputsHandle->ptrAt(i));
00130 }
00131
00132
00133 edm::Handle<reco::VertexCollection> pvCollection;
00134 iEvent.getByLabel(srcPVs_, pvCollection);
00135
00136 std::auto_ptr<std::vector<reco::TrackJet> > jets(new std::vector<reco::TrackJet>() );
00137
00138
00139 for (reco::VertexCollection::const_iterator itVtx = pvCollection->begin(); itVtx != pvCollection->end(); ++itVtx) {
00140 if (itVtx->isFake() || itVtx->ndof() < minVtxNdof_ || fabs(itVtx->z()) > maxVtxZ_) continue;
00141
00142
00143 inputs_.clear();
00144 fjInputs_.clear();
00145 fjJets_.clear();
00146
00147
00148 if (useOnlyVertexTracks_) {
00149
00150 for (reco::Vertex::trackRef_iterator itTr = itVtx->tracks_begin(); itTr != itVtx->tracks_end(); ++itTr) {
00151
00152 bool found = false;
00153
00154 for (std::vector<edm::Ptr<reco::RecoChargedRefCandidate> >::iterator itIn = allInputs.begin(); itIn != allInputs.end(); ++itIn) {
00155
00156 reco::TrackRef trref(itTr->castTo<reco::TrackRef>());
00157
00158 if ((*itIn)->track() == trref) {
00159 found = true;
00160
00161 inputs_.push_back(*itIn);
00162
00163 allInputs.erase(itIn);
00164
00165 break;
00166 }
00167 }
00168
00169 if (!found) edm::LogInfo("FastjetTrackJetProducer") << "Ignoring a track at vertex which is not in input track collection!";
00170 }
00171
00172 } else {
00173
00174 for (std::vector<edm::Ptr<reco::RecoChargedRefCandidate> >::iterator itIn = allInputs.begin(); itIn != allInputs.end(); ++itIn) {
00175
00176 float dz = (*itIn)->track()->dz(itVtx->position());
00177 float dxy = (*itIn)->track()->dxy(itVtx->position());
00178 if (fabs(dz) > dzTrVtxMax_) continue;
00179 if (fabs(dxy) > dxyTrVtxMax_) continue;
00180 bool closervtx = false;
00181
00182 for (reco::VertexCollection::const_iterator itVtx2 = pvCollection->begin(); itVtx2 != pvCollection->end(); ++itVtx2) {
00183 if (itVtx->isFake() || itVtx->ndof() < minVtxNdof_ || fabs(itVtx->z()) > maxVtxZ_) continue;
00184
00185 if (!useOnlyOnePV_ &&
00186 itVtx != itVtx2 &&
00187 fabs((*itIn)->track()->dz(itVtx2->position())) < fabs(dz)) {
00188 closervtx = true;
00189 break;
00190 }
00191 }
00192
00193 if (closervtx) continue;
00194
00195 inputs_.push_back(*itIn);
00196
00197 allInputs.erase(itIn);
00198
00199 --itIn;
00200 }
00201 }
00202
00203
00204 fjInputs_.reserve(inputs_.size());
00205 inputTowers();
00206 LogDebug("FastjetTrackJetProducer") << "Inputted towers\n";
00207
00208
00209 runAlgorithm(iEvent, iSetup);
00210 LogDebug("FastjetTrackJetProducer") << "Ran algorithm\n";
00211
00212
00213 for (unsigned int ijet=0;ijet<fjJets_.size();++ijet) {
00214
00215 std::vector<fastjet::PseudoJet> fjConstituents = sorted_by_pt(fjClusterSeq_->constituents(fjJets_[ijet]));
00216
00217 std::vector<reco::CandidatePtr> constituents = getConstituents(fjConstituents);
00218
00219 reco::TrackJet jet;
00220
00221 writeSpecific( jet,
00222 reco::Particle::LorentzVector(fjJets_[ijet].px(), fjJets_[ijet].py(), fjJets_[ijet].pz(), fjJets_[ijet].E()),
00223 vertex_, constituents, iSetup);
00224 jet.setJetArea(0);
00225 jet.setPileup(0);
00226 jet.setPrimaryVertex(edm::Ref<reco::VertexCollection>(pvCollection, (int) (itVtx-pvCollection->begin())));
00227 jet.setVertex(itVtx->position());
00228 jets->push_back(jet);
00229 }
00230
00231 if (useOnlyOnePV_) break;
00232 }
00233
00234
00235 LogDebug("FastjetTrackJetProducer") << "Put " << jets->size() << " jets in the event.\n";
00236 iEvent.put(jets);
00237
00238 }
00239
00240
00241
00242 void FastjetJetProducer::runAlgorithm( edm::Event & iEvent, edm::EventSetup const& iSetup)
00243 {
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 if ( !doAreaFastjet_ && !doRhoFastjet_) {
00264 fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequence( fjInputs_, *fjJetDefinition_ ) );
00265 } else if (voronoiRfact_ <= 0) {
00266 fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequenceArea( fjInputs_, *fjJetDefinition_ , *fjActiveArea_ ) );
00267 } else {
00268 fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequenceVoronoiArea( fjInputs_, *fjJetDefinition_ , fastjet::VoronoiAreaSpec(voronoiRfact_) ) );
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278 fjJets_ = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
00279 }
00280
00281
00282
00284
00286
00287 DEFINE_FWK_MODULE(FastjetJetProducer);
00288