00001 #ifndef __SELECTOR_HH__
00002 #define __SELECTOR_HH__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "fastjet/PseudoJet.hh"
00035 #include "fastjet/GhostedAreaSpec.hh"
00036 #include <limits>
00037 #include <cmath>
00038
00039 FASTJET_BEGIN_NAMESPACE
00040
00041
00047 class Selector;
00048
00049
00057 class SelectorWorker {
00058 public:
00059
00060
00061
00063 virtual ~SelectorWorker() {}
00064
00065
00066
00067
00068
00071 virtual bool pass(const PseudoJet & jet) const = 0;
00072
00077 virtual void terminator(std::vector<const PseudoJet *> & jets) const {
00078 for (unsigned i = 0; i < jets.size(); i++) {
00079 if (jets[i] && !pass(*jets[i])) jets[i] = NULL;
00080 }
00081 }
00082
00084 virtual bool applies_jet_by_jet() const {return true;}
00085
00087 virtual std::string description() const {return "missing description";}
00088
00089
00090
00091
00092
00094 virtual bool is_relocatable() const { return false;}
00095
00097 virtual void relocate(const PseudoJet ¢re){
00098 throw Error("relocate undefined for a non-relocatable selector worker");
00099 }
00100
00105 virtual SelectorWorker* copy(){
00106 throw Error("this SelectorWorker has nothing to copy");
00107 }
00108
00109
00110
00111
00112
00114 virtual void get_rapidity_extent(double & rapmin, double & rapmax) const {
00115 rapmax = std::numeric_limits<double>::max();
00116 rapmin = -rapmax;
00117 }
00118
00120 virtual bool has_area() const { return false;}
00121
00123 virtual bool has_known_area() const { return false;}
00124
00126 virtual double known_area() const{
00127 throw Error("this selector has no computable area");
00128 }
00129
00130
00131
00132 };
00133
00134
00135
00136
00137
00138 class Selector{
00139 public:
00142 Selector() {}
00143
00148 Selector(SelectorWorker * worker) {_worker.reset(worker);}
00149
00151 virtual ~Selector(){}
00152
00154 bool pass(const PseudoJet & jet) const {
00155 if (!validated_worker()->applies_jet_by_jet()) {
00156 throw Error("Cannot apply this selector to an individual jet");
00157 }
00158 return _worker->pass(jet);
00159 }
00160
00162 bool operator()(const PseudoJet & jet) const {
00163 return pass(jet);
00164 }
00165
00167 bool applies_jet_by_jet() const {
00168 return validated_worker()->applies_jet_by_jet();
00169 }
00170
00172 std::vector<PseudoJet> operator()(const std::vector<PseudoJet> & jets) const;
00173
00175 void get_rapidity_extent(double &rapmin, double &rapmax) const {
00176 return validated_worker()->get_rapidity_extent(rapmin, rapmax);
00177 }
00178
00180 std::string description() const {
00181 return validated_worker()->description();
00182 }
00183
00185 bool has_area() const{
00186 return validated_worker()->has_area();
00187 }
00188
00198 double area(double cell_area=gas::def_ghost_area) const;
00199
00201 const SharedPtr<SelectorWorker> & worker() const {return _worker;}
00202
00204 const SelectorWorker* validated_worker() const {
00205 const SelectorWorker* worker_ptr = _worker.get();
00206 if (worker_ptr == 0) throw InvalidWorker();
00207 return worker_ptr;
00208 }
00209
00212 class InvalidWorker : public Error {
00213 public:
00214 InvalidWorker() : Error("Attempt to use Selector with no valid underlying worker") {}
00215 };
00216
00219 class InvalidArea : public Error {
00220 public:
00221 InvalidArea() : Error("Attempt to obtain area from Selector for which this is not meaningful") {}
00222 };
00223
00224
00225
00226
00227
00228 protected:
00237 void _copy_worker_if_needed(){
00238
00239 if (_worker.unique()) return;
00240
00241
00242
00243 _worker.reset(_worker->copy());
00244 }
00245 public:
00246
00248 bool is_relocatable() const {
00249 return validated_worker()->is_relocatable();
00250 }
00251
00253 const Selector & relocate(const PseudoJet ¢re){
00254
00255
00256 if (! validated_worker()->is_relocatable()){
00257 return *this;
00258 }
00259
00260
00261
00262 _copy_worker_if_needed();
00263
00264 _worker->relocate(centre);
00265 return *this;
00266 }
00267
00268 private:
00269 SharedPtr<SelectorWorker> _worker;
00270 };
00271
00272
00273
00274
00275
00276
00279
00280
00281
00282
00286 Selector operator!(const Selector & s);
00287
00291 Selector operator ||(const Selector & s1, const Selector & s2);
00292
00293
00301 Selector operator&&(const Selector & s1, const Selector & s2);
00302
00311 Selector operator*(const Selector & s1, const Selector & s2);
00312
00313
00314
00315
00316 Selector SelectorPtMin(double ptmin);
00317 Selector SelectorPtMax(double ptmax);
00318 Selector SelectorPtRange(double ptmin, double ptmax);
00319
00320 Selector SelectorEtMin(double Etmin);
00321 Selector SelectorEtMax(double Etmax);
00322 Selector SelectorEtRange(double Etmin, double Etmax);
00323
00324 Selector SelectorEMin(double Emin);
00325 Selector SelectorEMax(double Emax);
00326 Selector SelectorERange(double Emin, double Emax);
00327
00328 Selector SelectorMMin(double Mmin);
00329 Selector SelectorMMax(double Mmax);
00330 Selector SelectorMRange(double Mmin, double Mmax);
00331
00332 Selector SelectorRapMin(double rapmin);
00333 Selector SelectorRapMax(double rapmax);
00334 Selector SelectorRapRange(double rapmin, double rapmax);
00335
00336 Selector SelectorAbsRapMin(double absrapmin);
00337 Selector SelectorAbsRapMax(double absrapmax);
00338 Selector SelectorAbsRapRange(double absrapmin, double absrapmax);
00339
00340 Selector SelectorEtaMin(double etamin);
00341 Selector SelectorEtaMax(double etamax);
00342 Selector SelectorEtaRange(double etamin, double etamax);
00343
00344 Selector SelectorAbsEtaMin(double absetamin);
00345 Selector SelectorAbsEtaMax(double absetamax);
00346 Selector SelectorAbsEtaRange(double absetamin, double absetamax);
00347
00348 Selector SelectorPhiRange(double phimin, double phimax);
00349
00356 Selector SelectorRapPhiRange(double rapmin, double rapmax, double phimin, double phimax);
00357
00359 Selector SelectorNHardest(unsigned int n);
00360
00361
00362
00363
00364
00366 Selector SelectorCircle(const double & radius);
00367
00370 Selector SelectorDoughnut(const double & radius_in, const double & radius_out);
00371
00374 Selector SelectorStrip(const double & half_width);
00375
00379 Selector SelectorRectangle(const double & half_rap_width, const double & half_phi_width);
00380
00382
00383 FASTJET_END_NAMESPACE
00384
00385 #endif // __SELECTOR_HH__
00386