CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastJetFWLiteWrapper.cc
Go to the documentation of this file.
1 // File: FastJetFWLiteWrapper.cc
2 // Description: see FastJetProducer.h
3 // Author: Andreas Oehler, University Karlsruhe (TH)
4 // Author: Dorian Kcira, Institut de Physique Nucleaire,
5 // Departement de Physique, Universite Catholique de Louvain
6 // Author: Joanna Weng, IPP, ETH Zurich
7 // Creation Date: Nov. 06 2006 Initial version.
8 //--------------------------------------------
9 
13 #include "fastjet/PseudoJet.hh"
14 #include "fastjet/ClusterSequence.hh"
15 #include "fastjet/ClusterSequenceActiveArea.hh"
16 #include <string.h>
17 #include "fastjet/ClusterSequence.hh"
18 #include "fastjet/ClusterSequenceActiveArea.hh"
19 // Wrapper around fastjet-package written by Matteo Cacciari and Gavin Salam.
20 //
21 // The algorithms that underlie FastJet have required considerable
22 // development and are described in hep-ph/0512210. If you use
23 // FastJet as part of work towards a scientific publication, please
24 // include a citation to the FastJet paper.
25 //
26 // Also see: http://www.lpthe.jussieu.fr/~salam/fastjet/
27 
29 
30 using namespace edm;
31 using namespace std;
32 
34  delete mJetDefinition;
35  delete mActiveArea;
36 }
37 
39  : mJetDefinition (0),
40  mActiveArea (0)
41 {
42 
43  //default ktRParam should be 1
44  theRparam_=1;
45  //default PtMin should be 10
46  thePtMin_=10.;
47  //default JetFinder should be "kt_algorithm"
48  string JetFinder="kt_algorithm";;
49  //default Strategy should be "Best"
50  string Strategy="Best";
51  //default dcut should be -1 (off)
52  theDcut_=-1.;
53  //default njets should be -1 (off)
54  theNjets_=-1;
55  //default UE_Subtraction should be false (off)
56  theDoSubtraction_=false;
57  //default Ghost_EtaMax should be 6
59  //default Active_Area_Repeats 5
61  //default GhostArea 0.01
62  theGhostArea_=0.01;
63  mActiveArea = new fastjet::ActiveAreaSpec ( theGhost_EtaMax_, theActive_Area_Repeats_ , theGhostArea_);
64 
65 
66  //configuring algorithm
67 
68 
69  fastjet::JetFinder jet_finder;
70  if (JetFinder=="cambridge_algorithm") jet_finder=fastjet::cambridge_algorithm;
71  else jet_finder=fastjet::kt_algorithm;
72 
73  //choosing search-strategy:
74 
75  fastjet::Strategy strategy;
76  if (Strategy=="N2Plain") strategy=fastjet::N2Plain;
77  // N2Plain is best for N<50
78  else if (Strategy=="N2Tiled") strategy=fastjet::N2Tiled;
79  // N2Tiled is best for 50<N<400
80  else if (Strategy=="N2MinHeapTiled") strategy=fastjet::N2MinHeapTiled;
81  // N2MinHeapTiles is best for 400<N<15000
82  else if (Strategy=="NlnN") strategy=fastjet::NlnN;
83  // NlnN is best for N>15000
84  else if (Strategy=="NlnNCam") strategy=fastjet::NlnNCam;
85  // NlnNCam is best for N>6000
86  else strategy=fastjet::Best;
87  // Chooses best Strategy for every event, depending on N and ktRParam
88 
89  //additional strategies are possible, but not documented in the manual as they are experimental,
90  //they are also not used by the "Best" method. Note: "NlnNCam" only works with
91  //the cambridge_algorithm and does not link against CGAL, "NlnN" is only
92  //available if fastjet is linked against CGAL.
93  //The above given numbers of N are for ktRaram=1.0, for other ktRParam the numbers would be
94  //different.
95 
96  theMode_=0;
97  if ((theNjets_!=-1)&&(theDcut_==-1)){
98  theMode_=3;
99  }
100  else if ((theNjets_==-1)&&(theDcut_!=-1)){
101  theMode_=2;
102  }
103  else if ((theNjets_!=-1)&&(theDcut_!=-1)){
104  cout <<"[FastJetWrapper] `njets` and `dcut` set!=-1! - running inclusive Mode"<<endl;
105  theMode_=1;
106  }
107  else {
108  theMode_=0;
109  }
110 
111  // theJetConfig_->theJetDef=fastjet::JetDefinition(jet_finder, theRparam_, strategy);
112  cout <<"*******************************************"<<endl;
113  cout <<"* Configuration of FastJet "<<endl;
114  if (theDoSubtraction_) cout <<"* running with ActiveAreaSubtraction(median)"<<endl;
115  switch (theMode_){
116  case 0:
117  cout <<"* Mode : inclusive"<<endl;
118  cout <<"* PtMin : "<<thePtMin_<<endl;
119  break;
120  case 1:
121  cout <<"* [WARNING] Mode : inclusive - dcut and njets set!"<<endl;
122  cout <<"* PtMin : "<<thePtMin_<<endl;
123  break;
124  case 2:
125  cout <<"* Mode : exclusive"<<endl;
126  cout <<"* dcut : "<<theDcut_<<endl;
127  break;
128  case 3:
129  cout <<"* Mode : exclusive"<<endl;
130  cout <<"* njets : "<<theNjets_<<endl;
131  break;
132  }
133  cout <<"* Rparam : "<<theRparam_<<endl;
134  cout <<"* JetFinder: "<<JetFinder<<endl;
135  cout <<"* Strategy : "<<Strategy<<endl;
136  cout <<"*******************************************"<<endl;
137 
138 }
139 
141  if (!fOutput) return;
142  fOutput->clear();
143 
144  // convert inputs
145  std::vector<fastjet::PseudoJet> fjInputs;
146  fjInputs.reserve (fInput.size());
147 
148  JetReco::InputCollection::const_iterator input = fInput.begin();
149  for (unsigned i = 0; i < fInput.size(); ++i) {
150  const JetReco::InputItem& c = fInput[i];
151  fjInputs.push_back (fastjet::PseudoJet (c->px(),c->py(),c->pz(),c->energy()));
152  fjInputs.back().set_user_index(i);
153  }
154 
155  // create an object that represents your choice of jet finder and
156  // the associated parameters
157  // run the jet clustering with the above jet definition
158 
159  // here we need to keep both pointers, as "area" interfaces are missing in base class
160  fastjet::ClusterSequenceActiveArea* clusterSequenceWithArea = 0;
161  fastjet::ClusterSequenceWithArea* clusterSequence = 0;
162  // if (mActiveArea) {
163  // clusterSequenceWithArea = new fastjet::ClusterSequenceActiveArea (fjInputs, *mJetDefinition, *mActiveArea);
164  // clusterSequence = clusterSequenceWithArea;
165  // }
166  // else {
167  clusterSequence = new fastjet::ClusterSequenceWithArea (fjInputs, *mJetDefinition);
168  // }
169  // retrieve jets for selected mode
170  std::vector<fastjet::PseudoJet> jets = clusterSequence->inclusive_jets (thePtMin_);
171 
172  // get PU pt
173  double median_Pt_Per_Area = clusterSequenceWithArea ? clusterSequenceWithArea->pt_per_unit_area() : 0.;
174 
175  // process found jets
176  for (std::vector<fastjet::PseudoJet>::const_iterator jet=jets.begin(); jet!=jets.end();++jet) {
177  // jet itself
178  double px=jet->px();
179  double py=jet->py();
180  double pz=jet->pz();
181  double E=jet->E();
182  double jetArea=clusterSequence->area(*jet);
183  double pu=0.;
184  // PU subtraction
185  if (clusterSequenceWithArea) {
186  fastjet::PseudoJet pu_p4 = median_Pt_Per_Area * clusterSequenceWithArea->area_4vector(*jet);
187  pu = pu_p4.E();
188  if (pu_p4.perp2() >= jet->perp2() || pu_p4.E() >= jet->E()) { // if the correction is too large, set the jet to zero
189  px = py = pz = E = 0.;
190  }
191  else { // otherwise do an E-scheme subtraction
192  px -= pu_p4.px();
193  py -= pu_p4.py();
194  pz -= pu_p4.pz();
195  E -= pu_p4.E();
196  }
197  }
198  math::XYZTLorentzVector p4(px,py,pz,E);
199  // constituents
200  std::vector<fastjet::PseudoJet> fastjet_constituents = clusterSequence->constituents(*jet);
201  JetReco::InputCollection jetConstituents;
202  jetConstituents.reserve (fastjet_constituents.size());
203  for (std::vector<fastjet::PseudoJet>::const_iterator itConst=fastjet_constituents.begin();
204  itConst!=fastjet_constituents.end();itConst++){
205  jetConstituents.push_back(fInput[(*itConst).user_index()]);
206  }
207  // Build ProtoJet
208  fOutput->push_back(ProtoJet(p4,jetConstituents));
209  fOutput->back().setJetArea (jetArea);
210  fOutput->back().setPileup (pu);
211  }
212  // cleanup
213  if (clusterSequenceWithArea) delete clusterSequenceWithArea;
214  else delete clusterSequence; // sigh... No plymorphism in fastjet
215 }
216 
217 
int i
Definition: DBlmapReader.cc:9
virtual double energy() const =0
energy
std::vector< ProtoJet > OutputCollection
Definition: JetRecoTypes.h:63
void run(const JetReco::InputCollection &fInput, JetReco::OutputCollection *fOutput)
std::vector< InputItem > InputCollection
Definition: JetRecoTypes.h:62
virtual double pz() const =0
z coordinate of momentum vector
Transient Jet class used by the reconstruction algorithms.
Definition: ProtoJet.h:25
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
double p4[4]
Definition: TauolaWrapper.h:92
virtual double py() const =0
y coordinate of momentum vector
tuple input
Definition: collect_tpl.py:10
virtual double px() const =0
x coordinate of momentum vector
fastjet::JetDefinition * mJetDefinition
tuple cout
Definition: gather_cfg.py:41
fastjet::ActiveAreaSpec * mActiveArea