Pid Framework
Loading...
Searching...
No Matches
Getter.h
Go to the documentation of this file.
1
8#ifndef PidGetter_H
9#define PidGetter_H 1
10
11#include "ParticleFit.h"
12#include "TObject.h"
13#include <TCutG.h>
14#include <TMultiGraph.h>
15#include <TText.h>
16#include <vector>
17
18namespace Pid {
19
24
25 public:
26 virtual ~BaseGetter() = default;
27
28 virtual double GetWeight(double var1, double var2, int pid) = 0;
29
30 virtual std::map<int, double> GetWeights(double var1, double var2) = 0;
31
32 virtual int GetPid(double var1, double var2, double purity) = 0;
33
34 virtual void Streamer(TBuffer&){};
35};
36
40class Getter : public TObject, public BaseGetter {
41 public:
42 void AddParticle(const ParticleFit& particle, uint id) { species_[id] = particle; }
43 void AddParticles(std::map<int, ParticleFit>&& species) { species_ = species; }
44
45 std::map<int, double> GetBayesianProbability(double p, double m2);
46 void SetRange(double min, double max) { minx_ = min, maxx_ = max; }
47
48 std::map<uint, double> GetSigma(double p, double m2) {
49 std::map<uint, double> sigma{};
50
51 if (p > maxx_ || p < minx_)
52 return sigma;
53
54 for (auto& specie : species_) {
55 sigma[specie.first] = abs(m2 - specie.second.GetMean(p)) / specie.second.GetSigma(p);
56 }
57 return sigma;
58 }
59
60 int GetPid(double p, double m2, double purity) override {
61 auto prob = GetBayesianProbability(p, m2);
62 for (auto& pid_prob : prob)
63 if (pid_prob.second >= purity) return pid_prob.first;
64 return 1;
65 }
66
67 double GetWeight(double var1, double var2, int pid) override {
68 // not yet implemented
69 return 1.0;
70 }
71 std::map<int, double> GetWeights(double var1, double var2) override {
72 return GetBayesianProbability(var1, var2);
73 }
74
75 const ParticleFit& GetParticleFit(int pid) {
76 auto it = species_.find(pid);
77 if (it != species_.end()) {
78 return it->second;
79 }
80 throw std::runtime_error("Particle " + std::to_string(pid) + " is not found!");
81 }
82
83 private:
84 std::map<int, ParticleFit> species_{};
85 double minx_{-100000.};
86 double maxx_{100000.};
87
88 ClassDefOverride(Getter, 1);
89};
90
94class CutGGetter : public TObject, public BaseGetter {
95
96 public:
97 void AddParticle(TCutG* cut, int pdgId) {
98 if (cut) {
99 auto insert_result = species_.insert({pdgId, {cut}});
100 if (!insert_result.second) {
101 (*insert_result.first).second.push_back(cut);
102 }
103 return;
104 }
105
106 throw std::logic_error("empty TCutG object");
107 }
108
109 int GetPid(double var1, double var2, double) override {
110
111 for (const auto& specie : species_) {
112 int pdgId = specie.first;
113 auto specieCuts = specie.second;
114
115 for (auto cut : specieCuts) {
116 if (cut->IsInside(var1, var2)) {
117 return pdgId;
118 }
119 }
120 }
121
122 return -1;
123 }
124
125 double GetWeight(double var1, double var2, int pid) override {
126 return 1.0 * (GetPid(var1, var2, 1) == pid);
127 }
128
129 std::map<int, double> GetWeights(double var1, double var2) override {
130 std::map<int, double> result;
131
132 for (const auto& specie : species_) {
133 result.insert({specie.first, GetWeight(var1, var2, specie.first)});
134 }
135
136 return {};
137 }
138
139 void Draw(Option_t* option = "") override {
140 TObject::Draw(option);
141
142 TMultiGraph mg("mg", "");
143 TText pdgLabel;
144
145 for (const auto& specie : species_) {
146 auto specieCuts = specie.second;
147 for (auto cut : specieCuts) mg.Add(cut);
148 }
149
150 mg.DrawClone(option);
151
152 for (const auto& specie : species_) {
153 int pdgId = specie.first;
154 auto specieCuts = specie.second;
155
156 double xc, yc;
157 for (auto cut : specieCuts) {
158 cut->Center(xc, yc);
159 pdgLabel.DrawText(xc, yc, Form("%d", pdgId));
160 }
161 }
162 }
163
164 protected:
165 std::map<int, std::vector<TCutG*>> species_{};
166
167 ClassDefOverride(Pid::CutGGetter, 1)
168};
169
170}// namespace Pid
171#endif// PidGetter_H
interface class for Pid getters
Definition Getter.h:23
Pid getter based on graphical cut TCutG.
Definition Getter.h:94
Bayesian Pid getter.
Definition Getter.h:40
Class to store fit resuls for particle specie.
Definition ParticleFit.h:19