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 #include "fastjet/ClusterSequenceArea.hh"
20 // Wrapper around fastjet-package written by Matteo Cacciari and Gavin Salam.
21 //
22 // The algorithms that underlie FastJet have required considerable
23 // development and are described in hep-ph/0512210. If you use
24 // FastJet as part of work towards a scientific publication, please
25 // include a citation to the FastJet paper.
26 //
27 // Also see: http://www.lpthe.jussieu.fr/~salam/fastjet/
28 
30 
31 using namespace edm;
32 using namespace std;
33 
35  delete mJetDefinition;
36  delete mActiveArea;
37 }
38 
40  : mJetDefinition (0),
41  mActiveArea (0)
42 {
43 
44  //default ktRParam should be 1
45  theRparam_=1;
46  //default PtMin should be 10
47  thePtMin_=10.;
48  //default JetFinder should be "kt_algorithm"
49  string JetFinder="kt_algorithm";;
50  //default Strategy should be "Best"
51  string Strategy="Best";
52  //default dcut should be -1 (off)
53  theDcut_=-1.;
54  //default njets should be -1 (off)
55  theNjets_=-1;
56  //default UE_Subtraction should be false (off)
57  theDoSubtraction_=false;
58  //default Ghost_EtaMax should be 6
60  //default Active_Area_Repeats 5
62  //default GhostArea 0.01
63  theGhostArea_=0.01;
64  mActiveArea = new fastjet::GhostedAreaSpec ( theGhost_EtaMax_, theActive_Area_Repeats_ , theGhostArea_);
65 
66 
67  //configuring algorithm
68 
69 
70 // fastjet::JetFinder jet_finder;
71 // if (JetFinder=="cambridge_algorithm") jet_finder=fastjet::cambridge_algorithm;
72 // else jet_finder=fastjet::kt_algorithm;
73 
74  //choosing search-strategy:
75 
76 // fastjet::Strategy strategy;
77 // if (Strategy=="N2Plain") strategy=fastjet::N2Plain;
78 // // N2Plain is best for N<50
79 // else if (Strategy=="N2Tiled") strategy=fastjet::N2Tiled;
80 // // N2Tiled is best for 50<N<400
81 // else if (Strategy=="N2MinHeapTiled") strategy=fastjet::N2MinHeapTiled;
82 // // N2MinHeapTiles is best for 400<N<15000
83 // else if (Strategy=="NlnN") strategy=fastjet::NlnN;
84 // // NlnN is best for N>15000
85 // else if (Strategy=="NlnNCam") strategy=fastjet::NlnNCam;
86 // // NlnNCam is best for N>6000
87 // else strategy=fastjet::Best;
88 // // Chooses best Strategy for every event, depending on N and ktRParam
89 
90  //additional strategies are possible, but not documented in the manual as they are experimental,
91  //they are also not used by the "Best" method. Note: "NlnNCam" only works with
92  //the cambridge_algorithm and does not link against CGAL, "NlnN" is only
93  //available if fastjet is linked against CGAL.
94  //The above given numbers of N are for ktRaram=1.0, for other ktRParam the numbers would be
95  //different.
96 
97  theMode_=0;
98  if ((theNjets_!=-1)&&(theDcut_==-1)){
99  theMode_=3;
100  }
101  else if ((theNjets_==-1)&&(theDcut_!=-1)){
102  theMode_=2;
103  }
104  else if ((theNjets_!=-1)&&(theDcut_!=-1)){
105  cout <<"[FastJetWrapper] `njets` and `dcut` set!=-1! - running inclusive Mode"<<endl;
106  theMode_=1;
107  }
108  else {
109  theMode_=0;
110  }
111 
112  // theJetConfig_->theJetDef=fastjet::JetDefinition(jet_finder, theRparam_, strategy);
113  cout <<"*******************************************"<<endl;
114  cout <<"* Configuration of FastJet "<<endl;
115  if (theDoSubtraction_) cout <<"* running with ActiveAreaSubtraction(median)"<<endl;
116  switch (theMode_){
117  case 0:
118  cout <<"* Mode : inclusive"<<endl;
119  cout <<"* PtMin : "<<thePtMin_<<endl;
120  break;
121  case 1:
122  cout <<"* [WARNING] Mode : inclusive - dcut and njets set!"<<endl;
123  cout <<"* PtMin : "<<thePtMin_<<endl;
124  break;
125  case 2:
126  cout <<"* Mode : exclusive"<<endl;
127  cout <<"* dcut : "<<theDcut_<<endl;
128  break;
129  case 3:
130  cout <<"* Mode : exclusive"<<endl;
131  cout <<"* njets : "<<theNjets_<<endl;
132  break;
133  }
134  cout <<"* Rparam : "<<theRparam_<<endl;
135  cout <<"* JetFinder: "<<JetFinder<<endl;
136  cout <<"* Strategy : "<<Strategy<<endl;
137  cout <<"*******************************************"<<endl;
138 
139 }
140 
142  if (!fOutput) return;
143  fOutput->clear();
144 
145  // convert inputs
146  std::vector<fastjet::PseudoJet> fjInputs;
147  fjInputs.reserve (fInput.size());
148 
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::ClusterSequenceArea* clusterSequence = 0;
162  // if (mActiveArea) {
163  // clusterSequenceWithArea = new fastjet::ClusterSequenceActiveArea (fjInputs, *mJetDefinition, *mActiveArea);
164  // clusterSequence = clusterSequenceWithArea;
165  // }
166  // else {
167  clusterSequence = new fastjet::ClusterSequenceArea (fjInputs, *mJetDefinition, *mActiveArea);
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
fastjet::GhostedAreaSpec * mActiveArea
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
double p4[4]
Definition: TauolaWrapper.h:92
vector< PseudoJet > jets
virtual double py() const =0
y coordinate of momentum vector
virtual double px() const =0
x coordinate of momentum vector
fastjet::JetDefinition * mJetDefinition
tuple cout
Definition: gather_cfg.py:121