All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
PIDVariables.cc
Go to the documentation of this file.
1 #include <PIDVariables.hh>
2 
3 #include "TRandom3.h"
4 
5 
6 /*******************************************************
7  *
8  * Implementation of PIDVariable_base and its derived classes
9  * Only the Update(...) methods must be redefined
10  *
11  ******************************************************/
12 
13 TRandom3* PIDVariable_base::varRand = NULL;
14 
15 int PIDVariable_base::Update(EVENT::ReconstructedParticle* particle)
16 {
17  EVENT::ClusterVec cluvec=particle->getClusters();
18  EVENT::TrackVec trk = particle->getTracks();
19  TVector3 p3(particle->getMomentum());
20 
21  return Update(cluvec, trk, p3);
22 }
23 
24 double PIDVariable_base::BetheBloch(const PIDParticles::PIDParticle_base* hypothesis, const float p) {
25 
26  float bg=p/hypothesis->mass;
27  float b=sqrt(bg*bg/(1.0+bg*bg));
28  //Double_t g=bg/b;
29  float tmax=hypothesis->GetBBpars()[2]*TMath::Power(bg,2.0); ///(1.0+pars[3]*g+pars[4]);
30 
31  return (0.5*hypothesis->GetBBpars()[0]*TMath::Log(hypothesis->GetBBpars()[1]*TMath::Power(bg,2.0)*tmax)
32  - hypothesis->GetBBpars()[3]*b*b - hypothesis->GetBBpars()[4]*bg/2.0)/(b*b);
33 }
34 
35 
36 
37 /*** (ECAL+HCAL)/p ***/
38 
39 // 1/10 of the minimum reconstructible pT at ILD
40 const float PID_CaloTotal::pCut = .01;
41 
43  PIDVariable_base("CaloTotal", "(ECAL+HCAL)/p", "")
44 {}
45 
46 int PID_CaloTotal::Update(const EVENT::ClusterVec cluvec, const EVENT::TrackVec trax, const TVector3 p3)
47 {
48  float p = p3.Mag();
49  if(p < pCut) {
50  SetOutOfRange();
51  return MASK_InvalidMomentum;
52  }
53 
54  float ecal=0., hcal=0.;
55  if(cluvec.size()>0){
56  for(unsigned int i=0; i<cluvec.size(); i++){
57  FloatVec sde = cluvec[i]->getSubdetectorEnergies();
58  ecal += sde[0];
59  hcal += sde[1];
60  }
61  _value = (ecal +hcal) / p;
62  return 0;
63  }
64  else {
65  _value = 0.;
66  return MASK_EmptyClusters;
67  }
68 }
69 
70 
71 /*** ECAL/(ECAL+HCAL) ***/
72 
73 // If total calorimetric deposit smaller than 1 keV consider it as empty clusters
74 const float PID_CaloEFrac::caloCut = 1.e-6;
75 
77  PIDVariable_base("CaloEFrac", "ECAL/(ECAL+HCAL)", "")
78 {}
79 
80 int PID_CaloEFrac::Update(const EVENT::ClusterVec cluvec, const EVENT::TrackVec trax, const TVector3 p3)
81 {
82  float ecal=0., hcal=0.;
83  if(cluvec.size()>0){
84  for(unsigned int i=0; i<cluvec.size(); i++){
85  FloatVec sde = cluvec[i]->getSubdetectorEnergies();
86  ecal += sde[0];
87  hcal += sde[1];
88  }
89 
90  if ( ecal+hcal < caloCut ) {
91  SetOutOfRange();
92  return MASK_EmptyClusters;
93  }
94  else {
95  _value = ecal/(ecal+hcal) ;
96  return 0;
97  }
98  }
99  else {
100  SetOutOfRange();
101  return MASK_EmptyClusters;
102  }
103 }
104 
105 
106 /*** Muon System deposit ***/
107 
108 // If muon-system calorimetric deposit smaller than 1 keV consider it as empty clusters
109 const float PID_CaloMuSys::muSysCut = 1.e-6;
110 
112  PIDVariable_base("CaloMuSys", "E_{#mu system}", "GeV")
113 {}
114 
115 int PID_CaloMuSys::Update(const EVENT::ClusterVec cluvec, const EVENT::TrackVec trax, const TVector3 p3)
116 {
117  float mucal=0.;
118  if(cluvec.size()>0){
119  for(unsigned int i=0; i<cluvec.size(); i++){
120  FloatVec sde = cluvec[i]->getSubdetectorEnergies();
121  mucal += sde[2];
122  }
123  _value = mucal;
124  if(_value < muSysCut) {
125  if(varRand) {
126  _value += varRand->Gaus(0., 1.e-6);
127  }
128  }
129  return 0;
130  }
131  else {
132  SetOutOfRange();
133  return MASK_EmptyClusters;
134  }
135 }
136 
137 
138 /*** Cluster shapes Masakazu ***/
139 
141  PIDVariable_base("CluShapeChi2", "Cluster shape #chi^{2}", "")
142 {}
143 
144 int PID_CluShapeChi2::Update(const EVENT::ClusterVec cluvec, const EVENT::TrackVec trax, const TVector3 p3)
145 {
146  if (cluvec.size() < 1) {
147  SetOutOfRange();
148  return MASK_EmptyClusters;
149  }
150 
151  FloatVec shapes=cluvec[0]->getShape();
152  if(shapes.size()!=0){
153  _value = shapes[0];
154  if (_value < -.1 ) {
155  if(varRand) {
156  _value += varRand->Gaus(0., 1.e-6);
157  }
158  }
159  return 0;
160  }
161  else {
162  SetOutOfRange();
163  return MASK_EmptyShapes;
164  }
165 }
166 
168  PIDVariable_base("DiscrepancyL", "d_{Shower max} / d_{EM shower max}", "")
169 {}
170 
171 int PID_CluShapeLDiscr::Update(const EVENT::ClusterVec cluvec, const EVENT::TrackVec trax, const TVector3 p3)
172 {
173  if (cluvec.size() < 1) {
174  SetOutOfRange();
175  return MASK_EmptyClusters;
176  }
177 
178  FloatVec shapes=cluvec[0]->getShape();
179  if(shapes.size()!=0){
180  _value = shapes[5];
181  return 0;
182  }
183  else {
184  SetOutOfRange();
185  return MASK_EmptyShapes;
186  }
187 }
188 
190  PIDVariable_base("DiscrepancyT", "Absorption length", "R_{m}")
191 {}
192 
193 int PID_CluShapeTDiscr::Update(const EVENT::ClusterVec cluvec, const EVENT::TrackVec trax, const TVector3 p3)
194 {
195  if (cluvec.size() < 1) {
196  SetOutOfRange();
197  return MASK_EmptyClusters;
198  }
199 
200  FloatVec shapes=cluvec[0]->getShape();
201  if(shapes.size()!=0){
202  _value = shapes[3]/shapes[6];
203  return 0;
204  }
205  else {
206  SetOutOfRange();
207  return MASK_EmptyShapes;
208  }
209 }
210 
212  PIDVariable_base("Xl20", "xl20", "?")
213 {}
214 
215 int PID_CluShapeXl20::Update(const EVENT::ClusterVec cluvec, const EVENT::TrackVec trax, const TVector3 p3)
216 {
217  if (cluvec.size() < 1) {
218  SetOutOfRange();
219  return MASK_EmptyClusters;
220  }
221 
222  FloatVec shapes=cluvec[0]->getShape();
223  if(shapes.size()!=0){
224  _value = shapes[15]/(2.0*3.50);
225  return 0;
226  }
227  else {
228  SetOutOfRange();
229  return MASK_EmptyShapes;
230  }
231 }
232 
233 
234 /*** dE/dx - Chi2 and Log(Chi2) ***/
235 
237  PIDVariable_base(ref.Name(), ref.Description(), ref.Unit()),
238  _hypothesis(ref._hypothesis), _dEdx_MIP(ref._dEdx_MIP)
239  {}
240 
241 PID_dEdxChi2::PID_dEdxChi2(const PIDParticles::PIDParticle_base* hypothesis, const float dEdx_MIP) :
242  PIDVariable_base(TString::Format("dEdx_chi2_%s", hypothesis->Name()).Data(),
243  TString::Format("#chi2_{dE/dx %s}", hypothesis->Name()).Data(), ""),
244  _hypothesis(hypothesis), _dEdx_MIP(dEdx_MIP)
245 {}
246 
248 {
249  delete _hypothesis;
250 }
251 
252 int PID_dEdxChi2::Update(const EVENT::ClusterVec cluvec,
253  const EVENT::TrackVec trax, const TVector3 p3)
254 {
255  int result = 0;
256  float ExpdEdx = BetheBloch(_hypothesis, p3.Mag());
257  float dEdx;
258  if(trax.size() > 0) { dEdx = trax.at(0)->getdEdx(); }
259  else { dEdx = -_dEdx_MIP; result |= MASK_EmptyTracks; } // Keep an eye on get_dEdxChi2()...
260 
261  // Normalise dEdx to MIP
262  dEdx /= _dEdx_MIP;
263 
264  if(dEdx>1.e-15) {
265  //get chi2!!(so far 5% error assumed. conservative)
266  double normdev = (dEdx-ExpdEdx)/(0.05*dEdx);
267  _value = TMath::Sign(TMath::Power(normdev, 2), normdev); // Signed chi2
268  }
269  else {
270  _value = -FLT_MAX;
271  result |= MASK_ZerodEdx;
272  }
273 
274  return result;
275 
276 }
277 
279  PIDVariable_base(ref.Name(), ref.Description(), ref.Unit()),
280  _hypothesis(ref._hypothesis), _dEdx_MIP(ref._dEdx_MIP)
281  {}
282 
283 PID_dEdxLogChi2::PID_dEdxLogChi2(const PIDParticles::PIDParticle_base* hypothesis, const float dEdx_MIP) :
284  PIDVariable_base(Form("dEdx_LogChi2_%s", hypothesis->Name()),
285  Form("Log(#chi2_{dE/dx %s})", hypothesis->Name()), ""),
286  _hypothesis(hypothesis), _dEdx_MIP(dEdx_MIP)
287 {/*std::cout << _name << "; " << _description << "; " << _unit << std::endl;*/}
288 
290 {
291  delete _hypothesis;
292 }
293 
294 int PID_dEdxLogChi2::Update(const EVENT::ClusterVec cluvec,
295  const EVENT::TrackVec trax, const TVector3 p3)
296 {
297  int result = 0;
298  float ExpdEdx = BetheBloch(_hypothesis, p3.Mag());
299  float dEdx;
300  if(trax.size() > 0) { dEdx = trax.at(0)->getdEdx(); }
301  else { dEdx = -_dEdx_MIP; result |= MASK_EmptyTracks; } // Keep an eye on get_dEdxChi2()...
302 
303  // Normalise dEdx to MIP
304  dEdx /= _dEdx_MIP;
305 
306  if(dEdx>1.e-15) {
307  //get chi2!!(so far 5% error assumed. conservative)
308  float normdev = (dEdx-ExpdEdx)/(0.05*dEdx);
309  _value = TMath::Sign(float( 2.*TMath::Log(fabs(normdev)+FLT_MIN) ), normdev);
310  }
311  else {
312  _value = -FLT_MAX;
313  result |= MASK_ZerodEdx;
314  }
315 
316  return result;
317 
318 }
319 
320 
321 /*******************************************************
322  *
323  * Implementation of the PIDVariables base and derived
324  * classes
325  *
326  ******************************************************/
327 
328 
329 
331  _p(0.)
332 {}
333 
334 PIDVariables_base::PIDVariables_base(EVENT::ReconstructedParticle* particle) :
335  _p(0.)
336 {}
337 
339  _varVec.clear();
340 }
341 
342 
343 int PIDVariables_base::Update(EVENT::ReconstructedParticle* _particle) {
344  EVENT::ClusterVec cluvec=_particle->getClusters();
345  EVENT::TrackVec trk = _particle->getTracks();
346  TVector3 p3(_particle->getMomentum());
347 
348  return Update(cluvec, trk, p3);
349 }
350 
351 
352 int PIDVariables_base::Update(const EVENT::ClusterVec cluvec,
353  const EVENT::TrackVec trax, const TVector3 p3){
354 
355  int result = 0;
356  for (VarVec::iterator vit=_varVec.begin(); vit!=_varVec.end(); vit++) {
357  result |= (*vit)->Update(cluvec, trax, p3);
358  }
359  _p = p3.Mag();
360 
361  return result;
362 }
363 
364 
366  for (VarVec::iterator vit=_varVec.begin(); vit!=_varVec.end(); vit++)
367  { (*vit)->SetOutOfRange(); }
368 }
369 
371 /* for(unsigned int i=0; i<_varVec.size(); i++) {
372  delete _varVec.at(i);
373  }*/
374  _varVec.clear();
375 }
376 
377 
378 
379 /*** PIDVariables for the Likelihood PID processor ***/
380 
382 {
383  Populate();
384 }
385 
386 
387 PIDVariables_LLPID::PIDVariables_LLPID(EVENT::ReconstructedParticle* particle)
388 {
389  Populate();
390  Update(particle);
391 }
392 
393 
395 {}
396 
398 
399  _varVec.push_back(new PID_CaloTotal);
400  _varVec.push_back(new PID_CaloEFrac);
401  _varVec.push_back(new PID_CaloMuSys);
402 
403  _varVec.push_back(new PID_CluShapeChi2);
404  _varVec.push_back(new PID_CluShapeLDiscr);
405  _varVec.push_back(new PID_CluShapeTDiscr);
406  _varVec.push_back(new PID_CluShapeXl20);
407 
413 }
414 
415 
417 {
418  Populate();
419 }
420 
421 PIDVariables_MvaPid::PIDVariables_MvaPid(EVENT::ReconstructedParticle* particle)
422 {
423  Populate();
424  Update(particle);
425 }
426 
427 
429 {}
430 
431 int PIDVariables_MvaPid::Update(EVENT::ReconstructedParticle* particle)
432 {
433  int result = PIDVariables_base::Update(particle);
434  RefreshMvaVars();
435  return result;
436 }
437 
439 {
441  RefreshMvaVars();
442 }
443 
445 {
446  for(unsigned int i=0; i<_varVec.size(); i++) {
447  _mvaVars.at(i) = _varVec.at(i)->Value();
448  }
449 }
450 
452 
453  _varVec.push_back(new PID_CaloTotal);
454  _varVec.push_back(new PID_CaloEFrac);
455  _varVec.push_back(new PID_CaloMuSys);
456 
457  _varVec.push_back(new PID_CluShapeChi2);
458  _varVec.push_back(new PID_CluShapeLDiscr);
459  _varVec.push_back(new PID_CluShapeTDiscr);
460  _varVec.push_back(new PID_CluShapeXl20);
461 
467 
468  for(unsigned int i=0; i<_varVec.size(); i++) {
469  _mvaVars.push_back(0.);
470  }
471 }
const PIDParticles::PIDParticle_base * _hypothesis
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
const PIDParticles::PIDParticle_base * _hypothesis
virtual void SetOutOfRange()
virtual int Update(EVENT::ReconstructedParticle *)
virtual void Populate()
static double BetheBloch(const PIDParticles::PIDParticle_base *hypothesis, const float p)
Definition: PIDVariables.cc:24
virtual void SetOutOfRange()
virtual void SetOutOfRange()
virtual void SetOutOfRange()
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
static TRandom3 * varRand
Definition: PIDVariables.hh:79
const double _dEdx_MIP
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
static const PIDParticle_base pionProperties("pion", 211,.139570, BBparsPion)
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
const double _dEdx_MIP
virtual ~PIDVariables_LLPID()
static const short MASK_EmptyShapes
Definition: PIDVariables.hh:56
virtual void ClearVars()
static const PIDParticle_base muonProperties("muon", 13,.105658, BBparsMuon)
static const PIDParticle_base kaonProperties("kaon", 321,.493677, BBparsKaon)
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
Definition: PIDVariables.cc:80
const double * GetBBpars() const
Definition: PIDParticles.hh:51
static const float caloCut
virtual void Populate()
static const short MASK_ZerodEdx
Definition: PIDVariables.hh:57
virtual ~PIDVariables_MvaPid()
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
virtual void SetOutOfRange()
virtual int Update(EVENT::ReconstructedParticle *)
static const PIDParticle_base protonProperties("proton", 2212,.938272, BBparsProton)
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
virtual void SetOutOfRange()
Definition: PIDVariables.hh:95
static const float e
static const short MASK_InvalidMomentum
Definition: PIDVariables.hh:58
static const PIDParticle_base electronProperties("electron", 11,.000510998, BBparsElectron)
virtual void SetOutOfRange()
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
virtual int Update(const EVENT::ClusterVec, const EVENT::TrackVec, const TVector3 p3)
Definition: PIDVariables.cc:46
virtual ~PIDVariables_base()=0
PID_dEdxLogChi2(const PID_dEdxLogChi2 &)
virtual int Update(EVENT::ReconstructedParticle *)
Definition: PIDVariables.cc:15
virtual void SetOutOfRange()
PID_dEdxChi2(const PID_dEdxChi2 &)
virtual void SetOutOfRange()
static const float pCut
Definition: PIDVariables.hh:97
static const float muSysCut
static const short MASK_EmptyClusters
Definition: PIDVariables.hh:54
static const short MASK_EmptyTracks
Definition: PIDVariables.hh:55