11 #include "FJ_includes.h"
16 AliFJWrapper(const char *name, const char *title);
17 virtual ~AliFJWrapper();
19 virtual void AddInputVector (Double_t px, Double_t py, Double_t pz, Double_t E, Int_t index = -99999);
20 virtual void AddInputVector (const fastjet::PseudoJet& vec, Int_t index = -99999);
21 virtual void AddInputVectors(const std::vector<fastjet::PseudoJet>& vecs, Int_t offsetIndex = -99999);
22 virtual const char *ClassName() const { return "AliFJWrapper"; }
23 virtual void Clear(const Option_t* /*opt*/ = "");
24 virtual void CopySettingsFrom (const AliFJWrapper& wrapper);
25 virtual void GetMedianAndSigma(Double_t& median, Double_t& sigma, Int_t remove = 0) const;
26 fastjet::ClusterSequenceArea* GetClusterSequence() const { return fClustSeq; }
27 const std::vector<fastjet::PseudoJet> GetInputVectors() const { return fInputVectors; }
28 const std::vector<fastjet::PseudoJet> GetInclusiveJets() const { return fInclusiveJets; }
29 std::vector<fastjet::PseudoJet> GetJetConstituents(UInt_t idx) const;
30 Double_t GetMedianUsedForBgSubtraction() const { return fMedUsedForBgSub; }
31 const char* GetName() const { return fName; }
32 const char* GetTitle() const { return fTitle; }
33 Double_t GetJetArea (UInt_t idx) const;
34 fastjet::PseudoJet GetJetAreaVector (UInt_t idx) const;
35 Double_t GetJetSubtractedPt (UInt_t idx) const;
36 virtual std::vector<double> GetSubtractedJetsPts(Double_t median_pt = -1, Bool_t sorted = kFALSE);
40 void SetStrategy(const fastjet::Strategy &strat) { fStrategy = strat; }
41 void SetAlgorithm(const fastjet::JetAlgorithm &algor) { fAlgor = algor; }
42 void SetRecombScheme(const fastjet::RecombinationScheme &scheme) { fScheme = scheme; }
43 void SetAreaType(const fastjet::AreaType &atype) { fAreaType = atype; }
44 void SetNRepeats(Int_t nrepeat) { fNGhostRepeats = nrepeat; }
45 void SetGhostArea(Double_t gharea) { fGhostArea = gharea; }
46 void SetMaxRap(Double_t maxrap) { fMaxRap = maxrap; }
47 void SetR(Double_t r) { fR = r; }
48 void SetGridScatter(Double_t gridSc) { fGridScatter = gridSc; }
49 void SetKtScatter(Double_t ktSc) { fKtScatter = ktSc; }
50 void SetMeanGhostKt(Double_t meankt) { fMeanGhostKt = meankt; }
51 void SetPluginAlgor(Int_t plugin) { fPluginAlgor = plugin; }
52 void SetUseArea4Vector(Bool_t useA4v) { fUseArea4Vector = useA4v; }
53 void SetupAlgorithmfromOpt(const char *option);
54 void SetupAreaTypefromOpt(const char *option);
55 void SetupSchemefromOpt(const char *option);
56 void SetupStrategyfromOpt(const char *option);
61 std::vector<fastjet::PseudoJet> fInputVectors; //!
62 std::vector<fastjet::PseudoJet> fInclusiveJets; //!
63 std::vector<double> fSubtractedJetsPt; //!
64 fastjet::AreaDefinition *fAreaDef; //!
65 fastjet::VoronoiAreaSpec *fVorAreaSpec; //!
66 fastjet::GhostedAreaSpec *fGhostedAreaSpec; //!
67 fastjet::JetDefinition *fJetDef; //!
68 fastjet::JetDefinition::Plugin *fPlugin; //!
69 fastjet::RangeDefinition *fRange; //!
70 fastjet::ClusterSequenceArea *fClustSeq; //!
71 fastjet::Strategy fStrategy; //!
72 fastjet::JetAlgorithm fAlgor; //!
73 fastjet::RecombinationScheme fScheme; //!
74 fastjet::AreaType fAreaType; //!
75 Int_t fNGhostRepeats; //!
76 Double_t fGhostArea; //!
79 // no setters for the moment - used default values in the constructor
80 Double_t fGridScatter; //!
81 Double_t fKtScatter; //!
82 Double_t fMeanGhostKt; //!
83 Int_t fPluginAlgor; //!
85 Double_t fMedUsedForBgSub; //!
86 Bool_t fUseArea4Vector; //!
88 virtual void SubtractBackground(const Double_t median_pt = -1);
92 AliFJWrapper(const AliFJWrapper& wrapper);
93 AliFJWrapper& operator = (const AliFJWrapper& wrapper);
98 #ifdef AliFJWrapper_CXX
99 #undef AliFJWrapper_CXX
102 #pragma GCC system_header
105 namespace fj = fastjet;
107 //_________________________________________________________________________________________________
108 AliFJWrapper::AliFJWrapper(const char *name, const char *title)
114 , fSubtractedJetsPt ( )
117 , fGhostedAreaSpec (0)
122 , fStrategy (fj::Best)
123 , fAlgor (fj::kt_algorithm)
124 , fScheme (fj::BIpt_scheme)
125 , fAreaType (fj::active_area)
132 , fMeanGhostKt (1e-100)
134 , fMedUsedForBgSub (0)
135 , fUseArea4Vector (kFALSE)
140 //_________________________________________________________________________________________________
141 AliFJWrapper::~AliFJWrapper()
147 delete fGhostedAreaSpec;
154 //_________________________________________________________________________________________________
155 void AliFJWrapper::CopySettingsFrom(const AliFJWrapper& wrapper)
157 // Copy some settings.
158 // You very often want to keep most of the settings
159 // but change only the algorithm or R - do it after call to this function
161 fStrategy = wrapper.fStrategy;
162 fAlgor = wrapper.fAlgor;
163 fScheme = wrapper.fScheme;
164 fAreaType = wrapper.fAreaType;
165 fNGhostRepeats = wrapper.fNGhostRepeats;
166 fGhostArea = wrapper.fGhostArea;
167 fMaxRap = wrapper.fMaxRap;
169 fGridScatter = wrapper.fGridScatter;
170 fKtScatter = wrapper.fKtScatter;
171 fMeanGhostKt = wrapper.fMeanGhostKt;
172 fPluginAlgor = wrapper.fPluginAlgor;
173 fUseArea4Vector = wrapper.fUseArea4Vector;
176 //_________________________________________________________________________________________________
177 void AliFJWrapper::Clear(const Option_t */*opt*/)
179 // Simply clear the input vectors.
180 // Make sure done on every event if the instance is reused
181 // Reset the median to zero.
183 fInputVectors.clear();
184 fMedUsedForBgSub = 0;
186 // for the moment brute force delete everything
187 delete fAreaDef; fAreaDef = 0;
188 delete fVorAreaSpec; fVorAreaSpec = 0;
189 delete fGhostedAreaSpec; fGhostedAreaSpec = 0;
190 delete fJetDef; fJetDef = 0;
191 delete fPlugin; fPlugin = 0;
192 delete fRange; fRange = 0;
193 delete fClustSeq; fClustSeq = 0;
196 //_________________________________________________________________________________________________
197 void AliFJWrapper::AddInputVector(Double_t px, Double_t py, Double_t pz, Double_t E, Int_t index)
199 // Make the input pseudojet.
201 fastjet::PseudoJet inVec(px, py, pz, E);
203 if (index > -99999) {
204 inVec.set_user_index(index);
206 inVec.set_user_index(fInputVectors.size());
209 // add to the fj container of input vectors
210 fInputVectors.push_back(inVec);
213 //_________________________________________________________________________________________________
214 void AliFJWrapper::AddInputVector(const fj::PseudoJet& vec, Int_t index)
216 // Add an input pseudojet.
218 fj::PseudoJet inVec = vec;
220 if (index > -99999) {
221 inVec.set_user_index(index);
223 inVec.set_user_index(fInputVectors.size());
226 // add to the fj container of input vectors
227 fInputVectors.push_back(inVec);
230 //_________________________________________________________________________________________________
231 void AliFJWrapper::AddInputVectors(const std::vector<fj::PseudoJet>& vecs, Int_t offsetIndex)
233 // Add the input from vector of pseudojets.
235 for (UInt_t i = 0; i < vecs.size(); ++i) {
236 fj::PseudoJet inVec = vecs[i];
237 if (offsetIndex > -99999)
238 inVec.set_user_index(fInputVectors.size() + offsetIndex);
239 // add to the fj container of input vectors
240 fInputVectors.push_back(inVec);
244 //_________________________________________________________________________________________________
245 Double_t AliFJWrapper::GetJetArea(UInt_t idx) const
249 Double_t retval = -1; // really wrong area..
250 if ( idx < fInclusiveJets.size() ) {
251 retval = fClustSeq->area(fInclusiveJets[idx]);
253 AliError(Form("[e] ::GetJetArea wrong index: %d",idx));
258 //_________________________________________________________________________________________________
259 fastjet::PseudoJet AliFJWrapper::GetJetAreaVector(UInt_t idx) const
261 // Get the jet area as vector.
262 fastjet::PseudoJet retval;
263 if ( idx < fInclusiveJets.size() ) {
264 retval = fClustSeq->area_4vector(fInclusiveJets[idx]);
266 AliError(Form("[e] ::GetJetArea wrong index: %d",idx));
271 //_________________________________________________________________________________________________
272 std::vector<double> AliFJWrapper::GetSubtractedJetsPts(Double_t median_pt, Bool_t sorted)
274 // Get subtracted jets pTs, returns vector.
276 SubtractBackground(median_pt);
278 if (kTRUE == sorted) {
279 std::sort(fSubtractedJetsPt.begin(), fSubtractedJetsPt.begin());
281 return fSubtractedJetsPt;
284 //_________________________________________________________________________________________________
285 Double_t AliFJWrapper::GetJetSubtractedPt(UInt_t idx) const
287 // Get subtracted jets pTs, returns Double_t.
289 Double_t retval = -99999.; // really wrong pt..
290 if ( idx < fSubtractedJetsPt.size() ) {
291 retval = fSubtractedJetsPt[idx];
296 //_________________________________________________________________________________________________
297 std::vector<fastjet::PseudoJet>
298 AliFJWrapper::GetJetConstituents(UInt_t idx) const
300 // Get jets constituents.
302 std::vector<fastjet::PseudoJet> retval;
304 if ( idx < fInclusiveJets.size() ) {
305 retval = fClustSeq->constituents(fInclusiveJets[idx]);
307 AliError(Form("[e] ::GetJetConstituents wrong index: %d",idx));
313 //_________________________________________________________________________________________________
314 void AliFJWrapper::GetMedianAndSigma(Double_t &median, Double_t &sigma, Int_t remove) const
316 // Get the median and sigma from fastjet.
317 // User can also do it on his own because the cluster sequence is exposed (via a getter)
320 AliError("[e] Run the jfinder first.");
324 Double_t mean_area = 0;
327 fClustSeq->get_median_rho_and_sigma(*fRange, fUseArea4Vector, median, sigma, mean_area);
329 std::vector<fastjet::PseudoJet> input_jets = sorted_by_pt(fClustSeq->inclusive_jets());
330 input_jets.erase(input_jets.begin(), input_jets.begin() + remove);
331 fClustSeq->get_median_rho_and_sigma(input_jets, *fRange, kFALSE, median, sigma, mean_area);
334 } catch (fj::Error) {
335 AliError(" [w] FJ Exception caught.");
341 //_________________________________________________________________________________________________
342 Int_t AliFJWrapper::Run()
344 // Run the actual jet finder.
346 if (fAreaType == fj::voronoi_area) {
347 // Rfact - check dependence - default is 1.
348 // NOTE: hardcoded variable!
349 fVorAreaSpec = new fj::VoronoiAreaSpec(1.);
350 fAreaDef = new fj::AreaDefinition(*fVorAreaSpec);
352 fGhostedAreaSpec = new fj::GhostedAreaSpec(fMaxRap,
359 fAreaDef = new fj::AreaDefinition(*fGhostedAreaSpec, fAreaType);
362 // this is acceptable by fastjet:
363 fRange = new fj::RangeDefinition(fMaxRap - 0.95 * fR);
365 if (fAlgor == fj::plugin_algorithm) {
366 if (fPluginAlgor == 0) {
368 // NOTE: hardcoded split parameter
369 Double_t overlap_threshold = 0.75; // NOTE: this actually splits a lot: thr/min(pt1,pt2)
370 fPlugin = new fj::SISConePlugin(fR,
372 0, //search of stable cones - zero = until no more
373 1.0); // this should be seed effectively for proto jets
374 fJetDef = new fastjet::JetDefinition(fPlugin);
376 AliError("[e] Unrecognized plugin number!");
379 fJetDef = new fj::JetDefinition(fAlgor, fR, fScheme, fStrategy);
383 fClustSeq = new fj::ClusterSequenceArea(fInputVectors, *fJetDef, *fAreaDef);
384 } catch (fj::Error) {
385 AliError(" [w] FJ Exception caught.");
390 fInclusiveJets.clear();
391 fInclusiveJets = fClustSeq->inclusive_jets(0.0);
396 //_________________________________________________________________________________________________
397 void AliFJWrapper::SubtractBackground(Double_t median_pt)
399 // Subtract the background (specify the value - see below the meaning).
400 // Negative argument means the bg will be determined with the current algorithm
401 // this is the default behavior. Zero is allowed
402 // Note: user may set the switch for area4vector based subtraction.
406 Double_t mean_area = 0;
408 // clear the subtracted jet pt's vector<double>
409 fSubtractedJetsPt.clear();
411 // check what was specified (default is -1)
414 fClustSeq->get_median_rho_and_sigma(*fRange, kFALSE, median, sigma, mean_area);
418 AliError(" [w] FJ Exception caught.");
421 fMedUsedForBgSub = median;
424 fMedUsedForBgSub = median;
426 // we do not know the sigma in this case
428 if (0.0 == median_pt) {
429 // AliWarning(Form(" [w] Median specified for bg subtraction is ZERO: %f", median_pt )) << endl;
430 fMedUsedForBgSub = 0.;
432 fMedUsedForBgSub = median_pt;
437 for (unsigned i = 0; i < fInclusiveJets.size(); i++) {
438 if (kTRUE == fUseArea4Vector) {
439 // subtract the background using the area4vector
440 fj::PseudoJet area4v = fClustSeq->area_4vector(fInclusiveJets[i]);
441 fj::PseudoJet jet_sub = fInclusiveJets[i] - area4v * fMedUsedForBgSub;
442 fSubtractedJetsPt.push_back(jet_sub.perp()); // here we put only the pt of the jet - note: this can be negative
444 // subtract the background using scalars
445 // fj::PseudoJet jet_sub = fInclusiveJets[i] - area * fMedUsedForBgSub_;
446 Double_t area = fClustSeq->area(fInclusiveJets[i]);
447 // standard subtraction
448 Double_t pt_sub = fInclusiveJets[i].perp() - fMedUsedForBgSub * area;
449 fSubtractedJetsPt.push_back(pt_sub); // here we put only the pt of the jet - note: this can be negative
454 //_________________________________________________________________________________________________
455 void AliFJWrapper::SetupAlgorithmfromOpt(const char *option)
457 // Setup algorithm from char.
459 std::string opt(option);
461 if (!opt.compare("kt")) fAlgor = fj::kt_algorithm;
462 if (!opt.compare("antikt")) fAlgor = fj::antikt_algorithm;
463 if (!opt.compare("cambridge")) fAlgor = fj::cambridge_algorithm;
464 if (!opt.compare("genkt")) fAlgor = fj::genkt_algorithm;
465 if (!opt.compare("cambridge_passive")) fAlgor = fj::cambridge_for_passive_algorithm;
466 if (!opt.compare("genkt_passive")) fAlgor = fj::genkt_for_passive_algorithm;
467 if (!opt.compare("ee_kt")) fAlgor = fj::ee_kt_algorithm;
468 if (!opt.compare("ee_genkt")) fAlgor = fj::ee_genkt_algorithm;
469 if (!opt.compare("plugin")) fAlgor = fj::plugin_algorithm;
472 //_________________________________________________________________________________________________
473 void AliFJWrapper::SetupAreaTypefromOpt(const char *option)
475 // Setup area type from char.
477 std::string opt(option);
479 if (!opt.compare("active")) fAreaType = fj::active_area;
480 if (!opt.compare("invalid")) fAreaType = fj::invalid_area;
481 if (!opt.compare("active_area_explicit_ghosts")) fAreaType = fj::active_area_explicit_ghosts;
482 if (!opt.compare("one_ghost_passive")) fAreaType = fj::one_ghost_passive_area;
483 if (!opt.compare("passive")) fAreaType = fj::passive_area;
484 if (!opt.compare("voronoi")) fAreaType = fj::voronoi_area;
487 //_________________________________________________________________________________________________
488 void AliFJWrapper::SetupSchemefromOpt(const char *option)
491 // setup scheme from char
494 std::string opt(option);
496 if (!opt.compare("BIpt")) fScheme = fj::BIpt_scheme;
497 if (!opt.compare("BIpt2")) fScheme = fj::BIpt2_scheme;
498 if (!opt.compare("E")) fScheme = fj::E_scheme;
499 if (!opt.compare("pt")) fScheme = fj::pt_scheme;
500 if (!opt.compare("pt2")) fScheme = fj::pt2_scheme;
501 if (!opt.compare("Et")) fScheme = fj::Et_scheme;
502 if (!opt.compare("Et2")) fScheme = fj::Et2_scheme;
505 //_________________________________________________________________________________________________
506 void AliFJWrapper::SetupStrategyfromOpt(const char *option)
508 // Setup strategy from char.
510 std::string opt(option);
512 if (!opt.compare("Best")) fStrategy = fj::Best;
513 if (!opt.compare("N2MinHeapTiled")) fStrategy = fj::N2MinHeapTiled;
514 if (!opt.compare("N2Tiled")) fStrategy = fj::N2Tiled;
515 if (!opt.compare("N2PoorTiled")) fStrategy = fj::N2PoorTiled;
516 if (!opt.compare("N2Plain")) fStrategy = fj::N2Plain;
517 if (!opt.compare("N3Dumb")) fStrategy = fj::N3Dumb;
518 if (!opt.compare("NlnN")) fStrategy = fj::NlnN;
519 if (!opt.compare("NlnN3pi")) fStrategy = fj::NlnN3pi;
520 if (!opt.compare("NlnN4pi")) fStrategy = fj::NlnN4pi;
521 if (!opt.compare("NlnNCam4pi")) fStrategy = fj::NlnNCam4pi;
522 if (!opt.compare("NlnNCam2pi2R")) fStrategy = fj::NlnNCam2pi2R;
523 if (!opt.compare("NlnNCam")) fStrategy = fj::NlnNCam;
524 if (!opt.compare("plugin")) fStrategy = fj::plugin_strategy;