All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
PIDParticles.hh
Go to the documentation of this file.
1 /*
2  * PIDParticles.hh
3  *
4  * PIDParticle
5  * Helper class that contains and manages parameters for a
6  * particle type, such as constant inherent particle properties
7  * and variable parameters used by PIDTools processors
8  *
9  * PIDParticles
10  * Helper struct (effectively no more than a namespace)
11  * to create a map of PIDParticle objects for use by PIDTools
12  * processors etc.
13  *
14  * Created on: Dec 23, 2015
15  * Author: S. Lukic
16  */
17 
18 #ifndef PIDPARTICLES_HH_
19 #define PIDPARTICLES_HH_
20 
21 #include "TMath.h"
22 #include "TMVA/Reader.h"
23 #include <map>
24 
25 #include "TH1F.h"
26 
27 
28 namespace PIDParticles
29 {
30 
32 public:
33 
35 
36  PIDParticle_base (const char *name, int _pdg, double _mass, const double* BBpars) :
37  pdg(_pdg), mass(_mass), _name(name)
38  {
39  for (int i=0; i<5; i++) _BBpars[i] = BBpars[i];
40  }
42  pdg(base.pdg), mass(base.mass), _name(base.Name())
43  {
44  for (int i=0; i<5; i++) _BBpars[i] = base.GetBBpars()[i];
45  }
46  ~PIDParticle_base() { /*delete _name;*/ }
47 
48  const int pdg;
49  const double mass;
50 
51  const double * GetBBpars() const { return _BBpars; }
52  const char* Name() const {return _name;}
53 
54 protected:
55  // There is no setter for BBpars - they are set in the constructor and do not change!
56  double _BBpars[5];
57 
58  const char *_name;
59 };
60 
61 
62 /*** Predefined intrinsic particle properties -- all constants in one place ***/
63 
65 
66 static const double BBparsElectron[5] = {-2.40638e-03, 7.10337e-01, 2.87718e-01, -1.71591e+00, 0.0};
67 static const double BBparsMuon[5] = {8.11408e-02, 9.92207e-01, 7.58509e+05, -1.70167e-01, 4.63670e-04};
68 static const double BBparsPion[5] = {8.10756e-02, -1.45051e+06, -3.09843e+04, 2.84056e-01, 3.38131e-04};
69 static const double BBparsKaon[5] = {7.96117e-02, 4.13335e+03, 1.13577e+06, 1.80555e-01, -3.15083e-04};
70 static const double BBparsProton[5] = {7.78772e-02, 4.49300e+04, 9.13778e+04, 1.50088e-01, -6.64184e-04};
71 
72 static const PIDParticle_base electronProperties("electron", 11, .000510998, BBparsElectron);
73 static const PIDParticle_base muonProperties("muon", 13, .105658, BBparsMuon);
74 static const PIDParticle_base pionProperties("pion", 211, .139570, BBparsPion);
75 static const PIDParticle_base kaonProperties("kaon", 321, .493677, BBparsKaon);
76 static const PIDParticle_base protonProperties("proton", 2212, .938272, BBparsProton);
77 
78 
79 /*** Derived classes ***/
80 
81 // PIDParticle with parameters for LikelihoodPID
82 
84 public:
85 
86  LLPIDHypothesis (const char *_name, int _pdg, double _mass,
87  float _prior, const double* _BBpars) :
88  PIDParticle_base(_name, _pdg, _mass, _BBpars),
89  prior(_prior), _posterior(0), _logL(0), _threshold(0)
90  { }
91 
92  LLPIDHypothesis (const PIDParticle_base &base, float _prior) :
93  PIDParticle_base(base),
94  prior(_prior), _posterior(0), _logL(0), _threshold(0)
95  { }
96 
98 
99  const float prior;
100 
101  double Posterior() const { return _posterior; }
102  double LogL() const { return _logL; }
103  double Threshold() const { return _threshold; }
104 
105  void SetPosterior(double posterior) { _posterior = posterior; }
106  void SetThreshold(double thr) { _threshold = thr; }
107 
108  void AddLogL(double logLpartial) { _logL += logLpartial; }
109 
110  void ResetLogL() { _logL=0.; }
111 
112 private:
113  double _posterior{}, _logL{};
114  double _threshold{};
115 };
116 
117 
118 
119 // PIDParticle with parameters for MVA PID
120 
122 public:
123 
124  MVAPIDHypothesis (const char *_name, int _pdg, double _mass, const double* _BBpars, const float mvaCut=0.) :
125  PIDParticle_base(_name, _pdg, _mass, _BBpars),
126  _mva(0), _q(0), _sigAbove(0), _mvaCut(mvaCut), _reader(new TMVA::Reader("Silent")),
127  _histoQ(NULL), _histoSig(NULL), _histoBkg(NULL)
128  { }
129 
130  MVAPIDHypothesis (const PIDParticle_base &base, const float mvaCut=0.) :
131  PIDParticle_base(base),
132  _mva(0), _q(0), _sigAbove(0), _mvaCut(mvaCut), _reader(new TMVA::Reader("Silent")),
133  _histoQ(NULL), _histoSig(NULL), _histoBkg(NULL)
134  { }
135 
136  ~MVAPIDHypothesis() { /*delete _reader;*/ };
137 
138  float GetMVAout() const { return _mva; }
139  float GetQ() const { return _q; }
140  float GetSigAbove() const { return _sigAbove; }
141  float GetMVAcut() const { return _mvaCut; }
142 
143 
144  void AddMVAVariable( const TString& name, Float_t* ptr)
145  { _reader->AddVariable(name, ptr); };
146  TMVA::IMethod* BookMVA(const TString& method, const TString& wfile)
147  { return _reader->BookMVA(method, wfile); } ;
148 
149  void Evaluate(const TString &method) ;
150 
151  void SetHistoQ(const TH1F *histoQ)
152  { _histoQ = (TH1F*)(histoQ->Clone("clonedQ")); _histoQ->SetDirectory(0); };
153  void SetHistoSig(const TH1F *histoSig)
154  { _histoSig = (TH1F*)(histoSig->Clone("clonedSig")); _histoSig->SetDirectory(0); };
155  void SetHistoBkg(const TH1F *histoBkg)
156  { _histoBkg = (TH1F*)(histoBkg->Clone("clonedBkg")); _histoBkg->SetDirectory(0); };
157  void SetMVACut(float mvaCut) { _mvaCut = mvaCut; } ;
158  bool PassesCut() const { return _mva > _mvaCut; } ;
159 
160 private:
161  float _mva{}, _q{}, _sigAbove{};
162  float _mvaCut{};
163  TMVA::Reader* _reader{};
164  TH1F *_histoQ{};
165  TH1F *_histoSig{};
166  TH1F *_histoBkg{};
167 };
168 
169 
170 
171 
172 typedef std::map<particleType, PIDParticle_base> ParticleMap;
173 typedef std::map<particleType, LLPIDHypothesis> LLHypothesesMap;
174 typedef std::map<particleType, MVAPIDHypothesis> MVAHypothesesMap;
175 
177 LLHypothesesMap* CreateLLPIDMap(std::vector<float> priors);
179 
180 }
181 
182 
183 #endif /* PIDPARTICLES_HH_ */
void SetHistoQ(const TH1F *histoQ)
void Evaluate(const TString &method)
Definition: PIDParticles.cc:80
TMVA::IMethod * BookMVA(const TString &method, const TString &wfile)
static const double BBparsProton[5]
Definition: PIDParticles.hh:70
ParticleMap * CreateParticleMap()
Definition: PIDParticles.cc:11
LLPIDHypothesis(const char *_name, int _pdg, double _mass, float _prior, const double *_BBpars)
Definition: PIDParticles.hh:86
std::map< particleType, PIDParticle_base > ParticleMap
void SetHistoSig(const TH1F *histoSig)
static const double BBparsMuon[5]
Definition: PIDParticles.hh:67
void SetPosterior(double posterior)
PIDParticle_base & operator=(const PIDParticle_base &)=delete
void AddMVAVariable(const TString &name, Float_t *ptr)
static const PIDParticle_base pionProperties("pion", 211,.139570, BBparsPion)
std::map< particleType, LLPIDHypothesis > LLHypothesesMap
LLHypothesesMap * CreateLLPIDMap(std::vector< float > priors)
Definition: PIDParticles.cc:34
void SetMVACut(float mvaCut)
static const double BBparsPion[5]
Definition: PIDParticles.hh:68
static const PIDParticle_base muonProperties("muon", 13,.105658, BBparsMuon)
static const PIDParticle_base kaonProperties("kaon", 321,.493677, BBparsKaon)
const double * GetBBpars() const
Definition: PIDParticles.hh:51
static const double BBparsElectron[5]
Definition: PIDParticles.hh:66
MVAHypothesesMap * CreateMVAPIDMap()
Definition: PIDParticles.cc:57
const char * Name() const
Definition: PIDParticles.hh:52
static const PIDParticle_base protonProperties("proton", 2212,.938272, BBparsProton)
void AddLogL(double logLpartial)
static const PIDParticle_base electronProperties("electron", 11,.000510998, BBparsElectron)
PIDParticle_base(const char *name, int _pdg, double _mass, const double *BBpars)
Definition: PIDParticles.hh:36
MVAPIDHypothesis(const char *_name, int _pdg, double _mass, const double *_BBpars, const float mvaCut=0.)
PIDParticle_base(const PIDParticle_base &base)
Definition: PIDParticles.hh:41
static const double BBparsKaon[5]
Definition: PIDParticles.hh:69
std::map< particleType, MVAPIDHypothesis > MVAHypothesesMap
void SetHistoBkg(const TH1F *histoBkg)
MVAPIDHypothesis(const PIDParticle_base &base, const float mvaCut=0.)
LLPIDHypothesis(const PIDParticle_base &base, float _prior)
Definition: PIDParticles.hh:92