Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-28 07:02:48

0001 /**
0002  \file
0003  Declaration of class Smear::Acceptance.
0004  
0005  \author    Michael Savastio
0006  \date      2011-08-19
0007  \copyright 2011 Brookhaven National Lab
0008  */
0009 
0010 #ifndef INCLUDE_EICSMEAR_SMEAR_ACCEPTANCE_H_
0011 #define INCLUDE_EICSMEAR_SMEAR_ACCEPTANCE_H_
0012 
0013 #include <set>
0014 #include <vector>
0015 
0016 #include <TFormula.h>
0017 #include <TMath.h>
0018 
0019 #include "eicsmear/smear/Smear.h"  // Definition of KinType
0020 
0021 typedef bool (*cutfunc)(const erhic::VirtualParticle&);
0022 
0023 class TString;
0024 
0025 namespace erhic {
0026 
0027 class VirtualParticle;
0028 
0029 }  // namespace erhic
0030 
0031 namespace Smear {
0032 
0033 /**
0034  Defines a range of acceptance in one or more of: theta, phi, E, p, pt, pz.
0035  Comprises one or more acceptance zones, which may or may not overlap.
0036  \todo Implement data hiding
0037  */
0038 class Acceptance {
0039  public:
0040   /**
0041    A (min, max) range in some variable evaluated as an arbitrary function
0042    of theta, phi, E and p (up to two supported).
0043    For example, if you want to set the acceptance in pT to [0.,100.]
0044    CustomCut("P*sin(theta)", 0., 100.);
0045    */
0046   class CustomCut {
0047    public:
0048     virtual ~CustomCut();
0049     CustomCut();
0050     CustomCut(const TString&, double min, double max);
0051     virtual bool Contains(const erhic::VirtualParticle&) const;
0052    protected:
0053     TFormula mFormula;
0054     int dim;
0055     KinType Kin1;
0056     KinType Kin2;
0057     double Min;
0058     double Max;
0059   };
0060 
0061   // Allows any function that takes a VirtualParticle
0062   // and a parameter vectior (mins and maxes, e.g.) and returns a boolean
0063   class CustomCutFunction {
0064     // typedef bool (*cutfunc)(const erhic::VirtualParticle& p, std::vector<double> params);
0065   public:
0066     virtual ~CustomCutFunction();
0067     CustomCutFunction( cutfunc func);
0068     // bool Contains(const erhic::VirtualParticle& p) const;
0069   protected:
0070     // std::vector<double> params;
0071     cutfunc func;
0072   };
0073 
0074   /**
0075    A single contiguous region of acceptance.
0076    */
0077   class Zone {
0078    public:
0079     /** Destructor */
0080     virtual ~Zone();
0081 
0082     /**
0083      Constructor.
0084      Define accepted ranges in theta, phi, E, p, pT and pz.
0085      Ranges in each variable are combined via boolean AND.
0086      By default accepts all particles.
0087      */
0088     Zone(double theta = 0., double = TMath::Pi(),
0089          double phi = 0., double = TMath::TwoPi(),
0090          double E = 0., double = TMath::Infinity(),
0091          double p = 0., double = TMath::Infinity(),
0092          double pt = 0., double = TMath::Infinity(),
0093          double pz = -TMath::Infinity(), double = TMath::Infinity());
0094 
0095     /**
0096      Add a CustomCut to the list of acceptance tests.
0097      */
0098     virtual void Add(const CustomCut&);
0099 
0100     /**
0101      Returns true if the particle lies in this zone, false if not.
0102      */
0103     virtual Bool_t Contains(const erhic::VirtualParticle&) const;
0104 
0105    protected:
0106     double thetaMin;
0107     double thetaMax;
0108     double phiMin;
0109     double phiMax;
0110     double EMin;
0111     double EMax;
0112     double PMin;
0113     double PMax;
0114     double pTMin;
0115     double pTMax;
0116     double pZMin;
0117     double pZMax;
0118     std::vector<Smear::Acceptance::CustomCut> CustomCuts;
0119     // We want to be able to write Acceptance objects to a ROOT file,
0120     // so nested classes need a dictionary as well.
0121     ClassDef(Smear::Acceptance::Zone, 1)
0122   };
0123 
0124   /** Destructor */
0125   virtual ~Acceptance();
0126 
0127   /**
0128    Default constructor.
0129    The genre sets which particle types are accepted (see Smear::EGenre).
0130    By default, the device has 4pi coverage,
0131    and accepts particles with all energy and momenta.
0132    */
0133   explicit Acceptance(int genre = kAll);
0134 
0135   /**
0136    Add a new zone with user-specified coverage.
0137    Particles will be accepted if they fall within any acceptance zone.
0138    */
0139   void AddZone(const Zone&);
0140 
0141   /**
0142    Returns the number of acceptance zones.
0143    */
0144   UInt_t GetNZones() const;
0145 
0146   /**
0147    Returns the "genre" of the particle (em, hadronic or all).
0148    */
0149   Int_t GetGenre() const;
0150 
0151   /**
0152    Select the class(es) of particles to accept.
0153    */
0154   void SetGenre(int genre);
0155 
0156   /**
0157    Select the charges of particles to accept.
0158    */
0159   void SetCharge(ECharge charge);
0160 
0161   /**
0162    Returns the charge of particles to accept.
0163    */
0164   ECharge GetCharge() const;
0165 
0166   /**
0167    Add a particle type to the list of particles to be smeared.
0168    If you never add anything, the device will
0169    smear all stable particles within its acceptance.
0170    Must use PDG particle codes.
0171    */
0172   void AddParticle(int particle);
0173 
0174   /**
0175    This function determines if the particle provided lies within
0176    the acceptance of the
0177    detector.  Default acceptance is a full 4*pi solid angle,
0178    with E and p in (0.,1e12) GeV.
0179    This function automatically fixes polar and azimuthal angles
0180    which are not within their proper range.
0181    */
0182   bool Is(const erhic::VirtualParticle& prt) const;
0183 
0184  protected:
0185   int mGenre;
0186   ECharge mCharge;  // Particle charges accepted (neutral, charged or all)
0187   std::vector<Zone> mZones;
0188   std::set<int> mParticles;
0189 
0190   ClassDef(Smear::Acceptance, 1)
0191 };
0192 
0193 inline UInt_t Acceptance::GetNZones() const {
0194   return mZones.size();
0195 }
0196 
0197 inline Int_t Acceptance::GetGenre() const {
0198   return mGenre;
0199 }
0200 
0201 inline ECharge Acceptance::GetCharge() const {
0202   return mCharge;
0203 }
0204 
0205 }  // namespace Smear
0206 
0207 #endif  // INCLUDE_EICSMEAR_SMEAR_ACCEPTANCE_H_