CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastjetJetProducer.cc
Go to the documentation of this file.
1 //
3 // FastjetJetProducer
4 // ------------------
5 //
6 // 04/21/2009 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
8 
10 
12 
18 
29 
30 
33 
34 #include "fastjet/SISConePlugin.hh"
35 #include "fastjet/CMSIterativeConePlugin.hh"
36 #include "fastjet/ATLASConePlugin.hh"
37 #include "fastjet/CDFMidPointPlugin.hh"
38 #include "fastjet/tools/Filter.hh"
39 #include "fastjet/tools/Pruner.hh"
40 #include "fastjet/tools/MassDropTagger.hh"
42 
43 #include <iostream>
44 #include <memory>
45 #include <algorithm>
46 #include <limits>
47 #include <cmath>
48 //#include <fstream>
49 
50 using namespace std;
51 
52 
53 
55 // construction / destruction
57 
58 //______________________________________________________________________________
60  : VirtualJetProducer( iConfig ),
61  useMassDropTagger_(false),
62  useFiltering_(false),
63  useTrimming_(false),
64  usePruning_(false),
65  useCMSBoostedTauSeedingAlgorithm_(false),
66  muCut_(-1.0),
67  yCut_(-1.0),
68  rFilt_(-1.0),
69  nFilt_(-1),
70  trimPtFracMin_(-1.0),
71  zCut_(-1.0),
72  RcutFactor_(-1.0)
73 {
74 
75  if ( iConfig.exists("UseOnlyVertexTracks") )
76  useOnlyVertexTracks_ = iConfig.getParameter<bool>("UseOnlyVertexTracks");
77  else
78  useOnlyVertexTracks_ = false;
79 
80  if ( iConfig.exists("UseOnlyOnePV") )
81  useOnlyOnePV_ = iConfig.getParameter<bool>("UseOnlyOnePV");
82  else
83  useOnlyOnePV_ = false;
84 
85  if ( iConfig.exists("DzTrVtxMax") )
86  dzTrVtxMax_ = iConfig.getParameter<double>("DzTrVtxMax");
87  else
88  dzTrVtxMax_ = 999999.;
89  if ( iConfig.exists("DxyTrVtxMax") )
90  dxyTrVtxMax_ = iConfig.getParameter<double>("DxyTrVtxMax");
91  else
92  dxyTrVtxMax_ = 999999.;
93  if ( iConfig.exists("MinVtxNdof") )
94  minVtxNdof_ = iConfig.getParameter<int>("MinVtxNdof");
95  else
96  minVtxNdof_ = 5;
97  if ( iConfig.exists("MaxVtxZ") )
98  maxVtxZ_ = iConfig.getParameter<double>("MaxVtxZ");
99  else
100  maxVtxZ_ = 15;
101 
102 
103  if ( iConfig.exists("useFiltering") ||
104  iConfig.exists("useTrimming") ||
105  iConfig.exists("usePruning") ||
106  iConfig.exists("useMassDropTagger") ||
107  iConfig.exists("useCMSBoostedTauSeedingAlgorithm") ) {
108  useMassDropTagger_=false;
109  useFiltering_=false;
110  useTrimming_=false;
111  usePruning_=false;
113  rFilt_=-1.0;
114  nFilt_=-1;
115  trimPtFracMin_=-1.0;
116  zCut_=-1.0;
117  RcutFactor_=-1.0;
118  muCut_=-1.0;
119  yCut_=-1.0;
120  subjetPtMin_ = -1.0;
121  muMin_ = -1.0;
122  muMax_ = -1.0;
123  yMin_ = -1.0;
124  yMax_ = -1.0;
125  dRMin_ = -1.0;
126  dRMax_ = -1.0;
127  maxDepth_ = -1;
128  useExplicitGhosts_ = true;
129 
130  if ( iConfig.exists("useMassDropTagger") ) {
131  useMassDropTagger_ = true;
132  muCut_ = iConfig.getParameter<double>("muCut");
133  yCut_ = iConfig.getParameter<double>("yCut");
134  }
135 
136  if ( iConfig.exists("useFiltering") ) {
137  useFiltering_ = true;
138  rFilt_ = iConfig.getParameter<double>("rFilt");
139  nFilt_ = iConfig.getParameter<int>("nFilt");
140  }
141 
142  if ( iConfig.exists("useTrimming") ) {
143  useTrimming_ = true;
144  rFilt_ = iConfig.getParameter<double>("rFilt");
145  trimPtFracMin_ = iConfig.getParameter<double>("trimPtFracMin");
146  }
147 
148  if ( iConfig.exists("usePruning") ) {
149  usePruning_ = true;
150  zCut_ = iConfig.getParameter<double>("zcut");
151  RcutFactor_ = iConfig.getParameter<double>("rcut_factor");
152  nFilt_ = iConfig.getParameter<int>("nFilt");
153  }
154 
155  if ( iConfig.exists("useCMSBoostedTauSeedingAlgorithm") ) {
156  useCMSBoostedTauSeedingAlgorithm_ = iConfig.getParameter<bool>("useCMSBoostedTauSeedingAlgorithm");
157  subjetPtMin_ = iConfig.getParameter<double>("subjetPtMin");
158  muMin_ = iConfig.getParameter<double>("muMin");
159  muMax_ = iConfig.getParameter<double>("muMax");
160  yMin_ = iConfig.getParameter<double>("yMin");
161  yMax_ = iConfig.getParameter<double>("yMax");
162  dRMin_ = iConfig.getParameter<double>("dRMin");
163  dRMax_ = iConfig.getParameter<double>("dRMax");
164  maxDepth_ = iConfig.getParameter<int>("maxDepth");
165  }
166 
167  }
168 
169 }
170 
171 
172 //______________________________________________________________________________
174 {
175 }
176 
177 
179 // implementation of member functions
181 
183 {
184 
185  // for everything but track jets
186  if (!makeTrackJet(jetTypeE)) {
187 
188  // use the default production from one collection
189  VirtualJetProducer::produce( iEvent, iSetup );
190 
191  } else { // produce trackjets from tracks grouped per primary vertex
192 
193  produceTrackJets(iEvent, iSetup);
194 
195  }
196 
197 }
198 
199 
201 {
202 
203  // read in the track candidates
205  iEvent.getByLabel(src_, inputsHandle);
206  // make collection with pointers so we can play around with it
207  std::vector<edm::Ptr<reco::RecoChargedRefCandidate> > allInputs;
208  std::vector<edm::Ptr<reco::Candidate> > origInputs;
209  for (size_t i = 0; i < inputsHandle->size(); ++i) {
210  allInputs.push_back(inputsHandle->ptrAt(i));
211  origInputs.push_back(inputsHandle->ptrAt(i));
212  }
213 
214  // read in the PV collection
216  iEvent.getByLabel(srcPVs_, pvCollection);
217  // define the overall output jet container
218  std::auto_ptr<std::vector<reco::TrackJet> > jets(new std::vector<reco::TrackJet>() );
219 
220  // loop over the good vertices, clustering for each vertex separately
221  for (reco::VertexCollection::const_iterator itVtx = pvCollection->begin(); itVtx != pvCollection->end(); ++itVtx) {
222  if (itVtx->isFake() || itVtx->ndof() < minVtxNdof_ || fabs(itVtx->z()) > maxVtxZ_) continue;
223 
224  // clear the intermediate containers
225  inputs_.clear();
226  fjInputs_.clear();
227  fjJets_.clear();
228 
229  // if only vertex-associated tracks should be used
230  if (useOnlyVertexTracks_) {
231  // loop over the tracks associated to the vertex
232  for (reco::Vertex::trackRef_iterator itTr = itVtx->tracks_begin(); itTr != itVtx->tracks_end(); ++itTr) {
233  // whether a match was found in the track candidate input
234  bool found = false;
235  // loop over input track candidates
236  for (std::vector<edm::Ptr<reco::RecoChargedRefCandidate> >::iterator itIn = allInputs.begin(); itIn != allInputs.end(); ++itIn) {
237  // match the input track candidate to the track from the vertex
238  reco::TrackRef trref(itTr->castTo<reco::TrackRef>());
239  // check if the tracks match
240  if ((*itIn)->track() == trref) {
241  found = true;
242  // add this track candidate to the input for clustering
243  inputs_.push_back(*itIn);
244  // erase the track candidate from the total list of input, so we don't reuse it later
245  allInputs.erase(itIn);
246  // found the candidate track corresponding to the vertex track, so stop the loop
247  break;
248  } // end if match found
249  } // end loop over input tracks
250  // give an info message in case no match is found (can happen if candidates are subset of tracks used for clustering)
251  if (!found) edm::LogInfo("FastjetTrackJetProducer") << "Ignoring a track at vertex which is not in input track collection!";
252  } // end loop over tracks associated to vertex
253  // if all inpt track candidates should be used
254  } else {
255  // loop over input track candidates
256  for (std::vector<edm::Ptr<reco::RecoChargedRefCandidate> >::iterator itIn = allInputs.begin(); itIn != allInputs.end(); ++itIn) {
257  // check if the track is close enough to the vertex
258  float dz = (*itIn)->track()->dz(itVtx->position());
259  float dxy = (*itIn)->track()->dxy(itVtx->position());
260  if (fabs(dz) > dzTrVtxMax_) continue;
261  if (fabs(dxy) > dxyTrVtxMax_) continue;
262  bool closervtx = false;
263  // now loop over the good vertices a second time
264  for (reco::VertexCollection::const_iterator itVtx2 = pvCollection->begin(); itVtx2 != pvCollection->end(); ++itVtx2) {
265  if (itVtx->isFake() || itVtx->ndof() < minVtxNdof_ || fabs(itVtx->z()) > maxVtxZ_) continue;
266  // and check this track is closer to any other vertex (if more than 1 vertex considered)
267  if (!useOnlyOnePV_ &&
268  itVtx != itVtx2 &&
269  fabs((*itIn)->track()->dz(itVtx2->position())) < fabs(dz)) {
270  closervtx = true;
271  break; // 1 closer vertex makes the track already not matched, so break
272  }
273  }
274  // don't add this track if another vertex is found closer
275  if (closervtx) continue;
276  // add this track candidate to the input for clustering
277  inputs_.push_back(*itIn);
278  // erase the track candidate from the total list of input, so we don't reuse it later
279  allInputs.erase(itIn);
280  // take a step back in the loop since we just erased
281  --itIn;
282  }
283  }
284 
285  // convert candidates in inputs_ to fastjet::PseudoJets in fjInputs_
286  fjInputs_.reserve(inputs_.size());
287  inputTowers();
288  LogDebug("FastjetTrackJetProducer") << "Inputted towers\n";
289 
290  // run algorithm, using fjInputs_, modifying fjJets_ and allocating fjClusterSeq_
291  runAlgorithm(iEvent, iSetup);
292  LogDebug("FastjetTrackJetProducer") << "Ran algorithm\n";
293 
294  // convert our jets and add to the overall jet vector
295  for (unsigned int ijet=0;ijet<fjJets_.size();++ijet) {
296  // get the constituents from fastjet
297  std::vector<fastjet::PseudoJet> fjConstituents = sorted_by_pt(fjClusterSeq_->constituents(fjJets_[ijet]));
298  // convert them to CandidatePtr vector
299  std::vector<reco::CandidatePtr> constituents = getConstituents(fjConstituents);
300  // fill the trackjet
302  // write the specifics to the jet (simultaneously sets 4-vector, vertex).
303  writeSpecific( jet,
304  reco::Particle::LorentzVector(fjJets_[ijet].px(), fjJets_[ijet].py(), fjJets_[ijet].pz(), fjJets_[ijet].E()),
305  vertex_, constituents, iSetup);
306  jet.setJetArea(0);
307  jet.setPileup(0);
308  jet.setPrimaryVertex(edm::Ref<reco::VertexCollection>(pvCollection, (int) (itVtx-pvCollection->begin())));
309  jet.setVertex(itVtx->position());
310  jets->push_back(jet);
311  }
312 
313  if (useOnlyOnePV_) break; // stop vertex loop if only one vertex asked for
314  } // end loop over vertices
315 
316  // put the jets in the collection
317  LogDebug("FastjetTrackJetProducer") << "Put " << jets->size() << " jets in the event.\n";
318  iEvent.put(jets);
319 
320 }
321 
322 
323 //______________________________________________________________________________
325 {
326  // run algorithm
327  /*
328  fjInputs_.clear();
329  double px, py , pz, E;
330  string line;
331  std::ifstream fin("dump3.txt");
332  while (getline(fin, line)){
333  if (line == "#END") break;
334  if (line.substr(0,1) == "#") {continue;}
335  istringstream istr(line);
336  istr >> px >> py >> pz >> E;
337  // create a fastjet::PseudoJet with these components and put it onto
338  // back of the input_particles vector
339  fastjet::PseudoJet j(px,py,pz,E);
340  //if ( fabs(j.rap()) < inputEtaMax )
341  fjInputs_.push_back(fastjet::PseudoJet(px,py,pz,E));
342  }
343  fin.close();
344  */
345 
346  if ( !doAreaFastjet_ && !doRhoFastjet_) {
347  fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequence( fjInputs_, *fjJetDefinition_ ) );
348  } else if (voronoiRfact_ <= 0) {
349  fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequenceArea( fjInputs_, *fjJetDefinition_ , *fjAreaDefinition_ ) );
350  } else {
351  fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequenceVoronoiArea( fjInputs_, *fjJetDefinition_ , fastjet::VoronoiAreaSpec(voronoiRfact_) ) );
352  }
353 
355  fjJets_ = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
356  } else {
357  fjJets_.clear();
358  std::vector<fastjet::PseudoJet> tempJets = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
359 
360  fastjet::MassDropTagger md_tagger( muCut_, yCut_ );
361  fastjet::contrib::CMSBoostedTauSeedingAlgorithm tau_tagger( subjetPtMin_, muMin_, muMax_, yMin_, yMax_, dRMin_, dRMax_, maxDepth_, verbosity_ );
362  fastjet::Filter trimmer( fastjet::Filter(fastjet::JetDefinition(fastjet::kt_algorithm, rFilt_), fastjet::SelectorPtFractionMin(trimPtFracMin_)));
363  fastjet::Filter filter( fastjet::Filter(fastjet::JetDefinition(fastjet::cambridge_algorithm, rFilt_), fastjet::SelectorNHardest(nFilt_)));
364  fastjet::Pruner pruner(fastjet::cambridge_algorithm, zCut_, RcutFactor_);
365 
366  std::vector<fastjet::Transformer const *> transformers;
367 
368  if ( useMassDropTagger_ ) {
369  transformers.push_back(&md_tagger);
370  }
372  transformers.push_back(&tau_tagger);
373  }
374  if ( useTrimming_ ) {
375  transformers.push_back(&trimmer);
376  }
377  if ( useFiltering_ ) {
378  transformers.push_back(&filter);
379  }
380  if ( usePruning_ ) {
381  transformers.push_back(&pruner);
382  }
383 
384  for ( std::vector<fastjet::PseudoJet>::const_iterator ijet = tempJets.begin(),
385  ijetEnd = tempJets.end(); ijet != ijetEnd; ++ijet ) {
386 
387  fastjet::PseudoJet transformedJet = *ijet;
388  bool passed = true;
389  for ( std::vector<fastjet::Transformer const *>::const_iterator itransf = transformers.begin(),
390  itransfEnd = transformers.end(); itransf != itransfEnd; ++itransf ) {
391  if ( transformedJet != 0 ) {
392  transformedJet = (**itransf)(transformedJet);
393  } else {
394  passed=false;
395  }
396  }
397  if ( passed ) {
398  fjJets_.push_back( transformedJet );
399  }
400  }
401  }
402 
403 }
404 
405 
406 
408 // define as cmssw plugin
410 
412 
#define LogDebug(id)
double muMin_
for CMSBoostedTauSeedingAlgorithm : subjet pt min
JetType::Type jetTypeE
T getParameter(std::string const &) const
double yMin_
for CMSBoostedTauSeedingAlgorithm : max mass-drop
bool useFiltering_
Mass-drop tagging for boosted Higgs.
int i
Definition: DBlmapReader.cc:9
double rFilt_
for mass-drop tagging, symmetry cut: min(pt1^2,pt2^2) * dR(1,2) / mjet &gt; ycut
tuple Filter
Definition: Filter_cff.py:5
reco::Particle::Point vertex_
double dRMax_
for CMSBoostedTauSeedingAlgorithm : min dR
double subjetPtMin_
for pruning: constituent dR * pt/2m &lt; rcut_factor
virtual std::vector< reco::CandidatePtr > getConstituents(const std::vector< fastjet::PseudoJet > &fjConstituents)
std::vector< fastjet::PseudoJet > fjJets_
virtual void setPileup(float fEnergy)
Set pileup energy contribution as calculated by algorithm.
Definition: Jet.h:108
virtual void inputTowers()
virtual void runAlgorithm(edm::Event &iEvent, const edm::EventSetup &iSetup)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
double RcutFactor_
for pruning: constituent minimum pt fraction of parent cluster
double yMax_
for CMSBoostedTauSeedingAlgorithm : min asymmetry
FastjetJetProducer(const edm::ParameterSet &iConfig)
bool useTrimming_
Jet filtering technique.
bool makeTrackJet(const JetType::Type &fTag)
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:103
std::vector< fastjet::PseudoJet > fjInputs_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
double trimPtFracMin_
for filtering, pruning: number of subjets expected
int iEvent
Definition: GenABIO.cc:243
bool usePruning_
Jet trimming technique.
std::vector< edm::Ptr< reco::Candidate > > inputs_
bool useCMSBoostedTauSeedingAlgorithm_
Jet pruning technique.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ClusterSequencePtr fjClusterSeq_
virtual void produceTrackJets(edm::Event &iEvent, const edm::EventSetup &iSetup)
vector< PseudoJet > jets
double muMax_
for CMSBoostedTauSeedingAlgorithm : min mass-drop
double muCut_
algorithm for seeding reconstruction of boosted Taus (similar to mass-drop tagging) ...
void setPrimaryVertex(const reco::VertexRef &vtx)
set associated primary vertex
Definition: TrackJet.cc:80
double dRMin_
for CMSBoostedTauSeedingAlgorithm : max asymmetry
double zCut_
for trimming: constituent minimum pt fraction of full jet
virtual void setVertex(const Point &vertex)
set vertex
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
Jets made out of tracks.
Definition: TrackJet.h:27
int nFilt_
for filtering, trimming: dR scale of sub-clustering
int maxDepth_
for CMSBoostedTauSeedingAlgorithm : max dR
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
double yCut_
for mass-drop tagging, m0/mjet (m0 = mass of highest mass subjet)
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:37
AreaDefinitionPtr fjAreaDefinition_
volatile std::atomic< bool > shutdown_flag false
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:27
boost::shared_ptr< fastjet::ClusterSequence > ClusterSequencePtr
void writeSpecific(reco::CaloJet &jet, reco::Particle::LorentzVector const &p4, reco::Particle::Point const &point, std::vector< reco::CandidatePtr > const &constituents, edm::EventSetup const &c)
Definition: JetSpecific.cc:41